mirror of
https://github.com/NoelFB/blah.git
synced 2025-06-29 19:25:26 +08:00
large organizational & cleanup refactor
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "blah/core/app.h"
|
||||
#include "blah/core/filesystem.h"
|
||||
#include "blah/core/common.h"
|
||||
#include "blah/core/time.h"
|
||||
#include "blah/app.h"
|
||||
#include "blah/filesystem.h"
|
||||
#include "blah/common.h"
|
||||
#include "blah/time.h"
|
||||
#include "blah/input.h"
|
||||
|
||||
#include "blah/containers/vector.h"
|
||||
#include "blah/containers/stackvector.h"
|
||||
@ -14,12 +15,12 @@
|
||||
#include "blah/graphics/subtexture.h"
|
||||
|
||||
#include "blah/graphics/blend.h"
|
||||
#include "blah/graphics/framebuffer.h"
|
||||
#include "blah/graphics/material.h"
|
||||
#include "blah/graphics/mesh.h"
|
||||
#include "blah/graphics/renderpass.h"
|
||||
#include "blah/graphics/sampler.h"
|
||||
#include "blah/graphics/shader.h"
|
||||
#include "blah/graphics/target.h"
|
||||
#include "blah/graphics/texture.h"
|
||||
|
||||
#include "blah/images/aseprite.h"
|
||||
@ -27,25 +28,21 @@
|
||||
#include "blah/images/image.h"
|
||||
#include "blah/images/packer.h"
|
||||
|
||||
#include "blah/input/input.h"
|
||||
#include "blah/input/binding.h"
|
||||
#include "blah/input/binding_registry.h"
|
||||
|
||||
#include "blah/math/calc.h"
|
||||
#include "blah/math/circle.h"
|
||||
#include "blah/math/color.h"
|
||||
#include "blah/math/ease.h"
|
||||
#include "blah/math/line.h"
|
||||
#include "blah/math/mat3x2.h"
|
||||
#include "blah/math/mat4x4.h"
|
||||
#include "blah/math/point.h"
|
||||
#include "blah/math/quad.h"
|
||||
#include "blah/math/rect.h"
|
||||
#include "blah/math/rectI.h"
|
||||
#include "blah/math/stopwatch.h"
|
||||
#include "blah/math/vec2.h"
|
||||
#include "blah/math/vec3.h"
|
||||
#include "blah/math/vec4.h"
|
||||
#include "blah/numerics/calc.h"
|
||||
#include "blah/numerics/circle.h"
|
||||
#include "blah/numerics/color.h"
|
||||
#include "blah/numerics/ease.h"
|
||||
#include "blah/numerics/line.h"
|
||||
#include "blah/numerics/mat3x2.h"
|
||||
#include "blah/numerics/mat4x4.h"
|
||||
#include "blah/numerics/point.h"
|
||||
#include "blah/numerics/quad.h"
|
||||
#include "blah/numerics/rect.h"
|
||||
#include "blah/numerics/rectI.h"
|
||||
#include "blah/numerics/vec2.h"
|
||||
#include "blah/numerics/vec3.h"
|
||||
#include "blah/numerics/vec4.h"
|
||||
|
||||
#include "blah/streams/bufferstream.h"
|
||||
#include "blah/streams/filestream.h"
|
||||
|
@ -1,15 +1,13 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
// Application Event Functions
|
||||
using AppEventFn = std::function<void()>;
|
||||
using AppEventFn = Func<void()>;
|
||||
|
||||
// Application Logging Functions
|
||||
using AppLogFn = std::function<void(const char* message, Log::Category category)>;
|
||||
using AppLogFn = Func<void(const char* message, Log::Category category)>;
|
||||
|
||||
// Application Configuration
|
||||
struct Config
|
||||
@ -90,8 +88,9 @@ namespace Blah
|
||||
int max_texture_size = 0;
|
||||
};
|
||||
|
||||
class FrameBuffer;
|
||||
using FrameBufferRef = std::shared_ptr<FrameBuffer>;
|
||||
// Forward declare Target for the BackBuffer
|
||||
class Target;
|
||||
using TargetRef = Ref<Target>;
|
||||
|
||||
// Application
|
||||
namespace App
|
||||
@ -145,6 +144,6 @@ namespace Blah
|
||||
const RendererFeatures& renderer_features();
|
||||
|
||||
// Reference to the window's back buffer
|
||||
extern const FrameBufferRef backbuffer;
|
||||
extern const TargetRef backbuffer;
|
||||
}
|
||||
}
|
56
include/blah/common.h
Normal file
56
include/blah/common.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
#include <cstdint> // for integer types
|
||||
#include <cstddef> // for size_t type
|
||||
#include <memory> // for std::shared_ptr
|
||||
#include <functional> // for std::function
|
||||
|
||||
// Asserts
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
#include <cstdlib> // for abort
|
||||
#define BLAH_ASSERT(condition, msg) \
|
||||
do { if (!(condition)) { Blah::Log::error("%s\n\tin %s:%d", (msg), __FILE__, __LINE__); abort(); } } while(0)
|
||||
#else
|
||||
#define BLAH_ASSERT(condition, msg) \
|
||||
do { if (!(condition)) { Blah::Log::error("%s\n\tin %s:%d", (msg), __FILE__, __LINE__); } } while(0)
|
||||
#endif
|
||||
|
||||
// maximum length of a print/warn/error message
|
||||
#ifndef BLAH_MESSAGE
|
||||
#define BLAH_MESSAGE 1024
|
||||
#endif
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
template<typename T>
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using WeakRef = std::weak_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using Func = std::function<T>;
|
||||
|
||||
namespace Log
|
||||
{
|
||||
enum class Category
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
void info(const char* message, ...);
|
||||
void warn(const char* message, ...);
|
||||
void error(const char* message, ...);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include <new>
|
||||
#include <initializer_list>
|
||||
|
||||
@ -16,7 +16,7 @@ namespace Blah
|
||||
int m_count;
|
||||
|
||||
public:
|
||||
static inline constexpr size_t MaxCapacity = Capacity;
|
||||
static constexpr size_t capacity = Capacity;
|
||||
|
||||
StackVector();
|
||||
StackVector(const std::initializer_list<T>& init);
|
||||
@ -30,7 +30,6 @@ namespace Blah
|
||||
void clear();
|
||||
|
||||
int size() const;
|
||||
constexpr int capacity() { return Capacity; }
|
||||
|
||||
T* expand(int amount = 1);
|
||||
void push_back(const T& item);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include <stdarg.h>
|
||||
#include <cstdio>
|
||||
#include <blah/containers/vector.h>
|
||||
@ -10,6 +10,7 @@ namespace Blah
|
||||
template<int T>
|
||||
class StrOf;
|
||||
using String = StrOf<64>;
|
||||
using FilePath = StrOf<260>;
|
||||
|
||||
// A simple String implementation
|
||||
class Str
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <type_traits>
|
||||
#include <blah/common.h>
|
||||
#include <initializer_list>
|
||||
#include <new>
|
||||
|
||||
@ -104,7 +103,7 @@ namespace Blah
|
||||
{
|
||||
m_buffer = nullptr;
|
||||
m_count = m_capacity = 0;
|
||||
reserve(list.size());
|
||||
reserve((int)list.size());
|
||||
for (auto& it : list)
|
||||
push_back(std::move(it));
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
// error / abort
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
|
||||
#include <stdlib.h>
|
||||
#define BLAH_ERROR(message) \
|
||||
do { Blah::Log::error(message "\n\tin file: %s:%d", __FILE__, __LINE__); abort(); } while(0)
|
||||
|
||||
#define BLAH_ERROR_FMT(message, ...) \
|
||||
do { Blah::Log::error(message "\n\tin file: %s:%d", __VA_ARGS__, __FILE__, __LINE__); abort(); } while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define BLAH_ERROR(message) \
|
||||
Blah::Log::error(message "\n\tin file: %s:%d", __FILE__, __LINE__)
|
||||
|
||||
#define BLAH_ERROR_FMT(message, ...) \
|
||||
Blah::Log::error(message "\n\tin file: %s:%d", __VA_ARGS__, __FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
||||
#define BLAH_ASSERT(condition, message) \
|
||||
do { if (!(condition)) { BLAH_ERROR(message); } } while(0)
|
||||
|
||||
#define BLAH_ASSERT_FMT(condition, message, ...) \
|
||||
do { if (!(condition)) { BLAH_ERROR_FMT(message, __VA_ARGS__); } } while(0)
|
||||
|
||||
// maximum length of a print/warn/error message
|
||||
#ifndef BLAH_MESSAGE
|
||||
#define BLAH_MESSAGE 1024
|
||||
#endif
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
namespace Log
|
||||
{
|
||||
enum class Category
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
void info(const char* message, ...);
|
||||
void warn(const char* message, ...);
|
||||
void error(const char* message, ...);
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/vector.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
using FilePath = StrOf<265>;
|
||||
class FileStream;
|
||||
|
||||
class File;
|
||||
using FileRef = Ref<File>;
|
||||
|
||||
enum class FileMode
|
||||
{
|
||||
// Opens an existing file for reading.
|
||||
@ -22,6 +23,41 @@ namespace Blah
|
||||
Create,
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
protected:
|
||||
File() = default;
|
||||
|
||||
public:
|
||||
// Opens a file at the given path.
|
||||
// If it fails, this will return an empty reference.
|
||||
static FileRef open(const FilePath& path, FileMode mode);
|
||||
|
||||
// checks if the given file exists
|
||||
static bool exists(const FilePath& path);
|
||||
|
||||
// deletes the given file
|
||||
static bool destroy(const FilePath& path);
|
||||
|
||||
// Default Destructor
|
||||
virtual ~File() = default;
|
||||
|
||||
// Gets the File Length
|
||||
virtual size_t length() = 0;
|
||||
|
||||
// Gets the current File Position
|
||||
virtual size_t position() = 0;
|
||||
|
||||
// Seeks to the given position in the File
|
||||
virtual size_t seek(size_t position) = 0;
|
||||
|
||||
// Reads from the File into the buffer, and returns how many bytes were successfully read
|
||||
virtual size_t read(unsigned char* buffer, size_t length) = 0;
|
||||
|
||||
// Writes from the buffer into the File, nd returns how many bytes were successfully written
|
||||
virtual size_t write(const unsigned char* buffer, size_t length) = 0;
|
||||
};
|
||||
|
||||
namespace Directory
|
||||
{
|
||||
// Creates a new directory at the given location.
|
||||
@ -32,7 +68,7 @@ namespace Blah
|
||||
bool exists(const FilePath& path);
|
||||
|
||||
// Tries to delete a path and returns whether it was successful
|
||||
bool remove(const FilePath& path);
|
||||
bool destroy(const FilePath& path);
|
||||
|
||||
// Enumerates over a directory and returns a list of files & directories
|
||||
Vector<FilePath> enumerate(const FilePath& path, bool recursive = true);
|
||||
@ -41,18 +77,6 @@ namespace Blah
|
||||
void explore(const FilePath& path);
|
||||
}
|
||||
|
||||
namespace File
|
||||
{
|
||||
// Checks if the given file exists
|
||||
bool exists(const FilePath& path);
|
||||
|
||||
// Tries to delete a file and returns whether it was successful
|
||||
bool remove(const FilePath& path);
|
||||
|
||||
// Opens the given file and returns a stream
|
||||
FileStream open(const FilePath& path, FileMode mode);
|
||||
}
|
||||
|
||||
namespace Path
|
||||
{
|
||||
// Returns the file name of the path
|
@ -1,17 +1,17 @@
|
||||
#pragma once
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/math/rect.h>
|
||||
#include <blah/math/mat3x2.h>
|
||||
#include <blah/math/mat4x4.h>
|
||||
#include <blah/math/color.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/numerics/rect.h>
|
||||
#include <blah/numerics/mat3x2.h>
|
||||
#include <blah/numerics/mat4x4.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/graphics/subtexture.h>
|
||||
#include <blah/graphics/spritefont.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <blah/graphics/blend.h>
|
||||
#include <blah/graphics/sampler.h>
|
||||
#include <blah/graphics/renderpass.h>
|
||||
#include <blah/core/app.h>
|
||||
#include <blah/app.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -125,10 +125,10 @@ namespace Blah
|
||||
void set_sampler(const TextureSampler& sampler);
|
||||
|
||||
// Draws the batch to the given target
|
||||
void render(const FrameBufferRef& target = App::backbuffer);
|
||||
void render(const TargetRef& target = App::backbuffer);
|
||||
|
||||
// Draws the batch to the given target, with the provided matrix
|
||||
void render(const FrameBufferRef& target, const Mat4x4& matrix);
|
||||
void render(const TargetRef& target, const Mat4x4& matrix);
|
||||
|
||||
// Clears the batch
|
||||
void clear();
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
#include <blah/math/color.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
enum class ClearMask
|
||||
{
|
||||
None = 0,
|
||||
Color = 1,
|
||||
Depth = 2,
|
||||
Stencil = 4,
|
||||
All = (int)Color | (int)Depth | (int)Stencil
|
||||
};
|
||||
|
||||
// Up to 4 color attachments + 1 depth/stencil
|
||||
using Attachments = StackVector<TextureRef, 5>;
|
||||
using AttachmentFormats = StackVector<TextureFormat, 5>;
|
||||
|
||||
class FrameBuffer;
|
||||
using FrameBufferRef = std::shared_ptr<FrameBuffer>;
|
||||
|
||||
// FrameBuffer is a 2D Buffer that can be drawn to.
|
||||
// It can hold up to 4 color Textures, and 1 Depth/Stencil Texture.
|
||||
class FrameBuffer
|
||||
{
|
||||
protected:
|
||||
FrameBuffer() = default;
|
||||
|
||||
public:
|
||||
// Copy / Moves not allowed
|
||||
FrameBuffer(const FrameBuffer&) = delete;
|
||||
FrameBuffer(FrameBuffer&&) = delete;
|
||||
FrameBuffer& operator=(const FrameBuffer&) = delete;
|
||||
FrameBuffer& operator=(FrameBuffer&&) = delete;
|
||||
|
||||
// Default Destructor
|
||||
virtual ~FrameBuffer() = default;
|
||||
|
||||
// Creates a new FrameBuffer with a single Color attachment
|
||||
// If the FrameBuffer creation fails, it will return an invalid FrameBufferRef.
|
||||
static FrameBufferRef create(int width, int height);
|
||||
|
||||
// Creates a new FrameBuffer with the given Texture Attachments. You must provide at least one Attachment.
|
||||
// If the FrameBuffer creation fails, it will return an invalid FrameBufferRef.
|
||||
static FrameBufferRef create(int width, int height, const AttachmentFormats& attachments);
|
||||
|
||||
// Gets the list of Attachments from the FrameBuffer
|
||||
virtual Attachments& attachments() = 0;
|
||||
|
||||
// Gets the list of Attachments from the FrameBuffer
|
||||
virtual const Attachments& attachments() const = 0;
|
||||
|
||||
// Gets the Attachment at a given index from the FrameBuffer
|
||||
TextureRef& attachment(int index);
|
||||
|
||||
// Gets the Attachment at a given index from the FrameBuffer
|
||||
const TextureRef& attachment(int index) const;
|
||||
|
||||
// Gets the width of the FrameBuffer
|
||||
virtual int width() const;
|
||||
|
||||
// Gets the height of the FrameBuffer
|
||||
virtual int height() const;
|
||||
|
||||
// Clears the FrameBuffer
|
||||
virtual void clear(Color color = Color::black, float depth = 1.0f, u8 stencil = 0, ClearMask mask = ClearMask::All) = 0;
|
||||
};
|
||||
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/graphics/sampler.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
class Material;
|
||||
typedef std::shared_ptr<Material> MaterialRef;
|
||||
using MaterialRef = Ref<Material>;
|
||||
|
||||
// Materials hold values that can be assigned to a shader during rendering
|
||||
class Material final
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <memory>
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
|
||||
namespace Blah
|
||||
@ -59,7 +58,7 @@ namespace Blah
|
||||
};
|
||||
|
||||
class Mesh;
|
||||
typedef std::shared_ptr<Mesh> MeshRef;
|
||||
using MeshRef = Ref<Mesh>;
|
||||
|
||||
// A Mesh is a set of Indices and Vertices which are used for drawing
|
||||
class Mesh
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/math/rect.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/rect.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/graphics/framebuffer.h>
|
||||
#include <blah/graphics/target.h>
|
||||
#include <blah/graphics/mesh.h>
|
||||
#include <blah/graphics/shader.h>
|
||||
#include <blah/graphics/material.h>
|
||||
@ -42,7 +42,7 @@ namespace Blah
|
||||
struct RenderPass
|
||||
{
|
||||
// Framebuffer to draw to
|
||||
FrameBufferRef target;
|
||||
TargetRef target;
|
||||
|
||||
// Mesh to draw with
|
||||
MeshRef mesh;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -70,7 +70,7 @@ namespace Blah
|
||||
};
|
||||
|
||||
class Shader;
|
||||
typedef std::shared_ptr<Shader> ShaderRef;
|
||||
using ShaderRef = Ref<Shader>;
|
||||
|
||||
// A shader used during Rendering
|
||||
class Shader
|
||||
|
@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <blah/graphics/subtexture.h>
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/filesystem.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Blah
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/math/rect.h>
|
||||
#include <blah/numerics/rect.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
72
include/blah/graphics/target.h
Normal file
72
include/blah/graphics/target.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include <blah/common.h>
|
||||
#include <blah/graphics/texture.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
#include <blah/numerics/color.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
enum class ClearMask
|
||||
{
|
||||
None = 0,
|
||||
Color = 1,
|
||||
Depth = 2,
|
||||
Stencil = 4,
|
||||
All = (int)Color | (int)Depth | (int)Stencil
|
||||
};
|
||||
|
||||
// Up to 4 color textures + 1 depth/stencil
|
||||
using Attachments = StackVector<TextureRef, 5>;
|
||||
using AttachmentFormats = StackVector<TextureFormat, 5>;
|
||||
|
||||
class Target;
|
||||
using TargetRef = Ref<Target>;
|
||||
|
||||
// Target is a 2D Buffer that can be drawn to.
|
||||
// It can hold up to 4 color Textures, and 1 Depth/Stencil Texture.
|
||||
class Target
|
||||
{
|
||||
protected:
|
||||
Target() = default;
|
||||
|
||||
public:
|
||||
// Copy / Moves not allowed
|
||||
Target(const Target&) = delete;
|
||||
Target(Target&&) = delete;
|
||||
Target& operator=(const Target&) = delete;
|
||||
Target& operator=(Target&&) = delete;
|
||||
|
||||
// Default Destructor
|
||||
virtual ~Target() = default;
|
||||
|
||||
// Creates a new Target with a single Color texture
|
||||
// If the Target creation fails, it will return an invalid TargetRef.
|
||||
static TargetRef create(int width, int height);
|
||||
|
||||
// Creates a new Target with the given Texture Attachments. You must provide at least one Attachment.
|
||||
// If the Target creation fails, it will return an invalid TargetRef.
|
||||
static TargetRef create(int width, int height, const AttachmentFormats& textures);
|
||||
|
||||
// Gets the list of Attachments from the Target
|
||||
virtual Attachments& textures() = 0;
|
||||
|
||||
// Gets the list of Attachments from the Target
|
||||
virtual const Attachments& textures() const = 0;
|
||||
|
||||
// Gets the Attachment at a given index from the Target
|
||||
TextureRef& texture(int index);
|
||||
|
||||
// Gets the Attachment at a given index from the Target
|
||||
const TextureRef& texture(int index) const;
|
||||
|
||||
// Gets the width of the Target
|
||||
virtual int width() const;
|
||||
|
||||
// Gets the height of the Target
|
||||
virtual int height() const;
|
||||
|
||||
// Clears the Target
|
||||
virtual void clear(Color color = Color::black, float depth = 1.0f, u8 stencil = 0, ClearMask mask = ClearMask::All) = 0;
|
||||
};
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -28,7 +28,7 @@ namespace Blah
|
||||
class Image;
|
||||
class Stream;
|
||||
class Texture;
|
||||
typedef std::shared_ptr<Texture> TextureRef;
|
||||
using TextureRef = Ref<Texture>;
|
||||
|
||||
// A 2D Texture held by the GPU to be used during rendering
|
||||
class Texture
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include <blah/math/color.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/images/image.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/streams/stream.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <blah/streams/stream.h>
|
||||
#include <blah/images/image.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include <blah/math/color.h>
|
||||
#include <blah/math/rectI.h>
|
||||
#include <blah/math/point.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/numerics/rectI.h>
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
#include <blah/images/image.h>
|
||||
#include <blah/math/color.h>
|
||||
#include <blah/math/rectI.h>
|
||||
#include <blah/math/point.h>
|
||||
#include <blah/numerics/color.h>
|
||||
#include <blah/numerics/rectI.h>
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <blah/streams/bufferstream.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
|
||||
// These are generally copied from the SDL2 Scancode Keys,
|
||||
// which are in turn based on the USB standards:
|
||||
@ -345,6 +346,306 @@ namespace Blah
|
||||
Right = 2,
|
||||
};
|
||||
|
||||
class InputBinding;
|
||||
using InputBindingRef = Ref<InputBinding>;
|
||||
|
||||
class AxisBinding;
|
||||
using AxisBindingRef = Ref<AxisBinding>;
|
||||
|
||||
class StickBinding;
|
||||
using StickBindingRef = Ref<StickBinding>;
|
||||
|
||||
// Single input Binding
|
||||
// You must call Binding::update() every frame to poll the input state.
|
||||
// Alternatively, bindings can be registered to Input which will
|
||||
// automatically update them.
|
||||
class InputBinding
|
||||
{
|
||||
public:
|
||||
|
||||
// Represents a Controller Trigger or a single direction of a Controller Axis.
|
||||
struct TriggerBind
|
||||
{
|
||||
// Controller Index we're bound to
|
||||
int controller = 0;
|
||||
|
||||
// The Axis we're bound to
|
||||
Axis axis = Axis::None;
|
||||
|
||||
// Minimum value of the axis
|
||||
float threshold = 0.01f;
|
||||
|
||||
// requires a positive value
|
||||
// otherwise requires a negative value
|
||||
bool positive = true;
|
||||
|
||||
TriggerBind() = default;
|
||||
TriggerBind(Axis axis);
|
||||
TriggerBind(int controller, Axis axis, float threshold, bool positive);
|
||||
|
||||
bool is_down(float axis_value) const;
|
||||
};
|
||||
|
||||
// Represents a Controller Button.
|
||||
struct ButtonBind
|
||||
{
|
||||
// Controller Index we're bound to
|
||||
int controller = 0;
|
||||
|
||||
// Button we're bound to
|
||||
Button button = Button::None;
|
||||
|
||||
ButtonBind() = default;
|
||||
ButtonBind(Button button);
|
||||
ButtonBind(int controller, Button button);
|
||||
};
|
||||
|
||||
// Input Buffer for press events
|
||||
float press_buffer = 0;
|
||||
|
||||
// Input Buffer for release events
|
||||
float release_buffer = 0;
|
||||
|
||||
// List of bound Keys
|
||||
StackVector<Key, 16> keys;
|
||||
|
||||
// List of bound Buttons
|
||||
StackVector<ButtonBind, 16> buttons;
|
||||
|
||||
// List of bound Triggers / Axis
|
||||
StackVector<TriggerBind, 16> triggers;
|
||||
|
||||
// List of bound Mouse buttons
|
||||
StackVector<MouseButton, 16> mouse;
|
||||
|
||||
InputBinding() = default;
|
||||
|
||||
InputBinding(float press_buffer)
|
||||
: press_buffer(press_buffer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
InputBinding(float press_buffer, const Args&... args)
|
||||
: press_buffer(press_buffer)
|
||||
{
|
||||
add(args...);
|
||||
}
|
||||
|
||||
// if the binding has been pressed
|
||||
bool pressed() const;
|
||||
|
||||
// if the binding has been released
|
||||
bool released() const;
|
||||
|
||||
// if the binding is currently held
|
||||
bool down() const;
|
||||
|
||||
// returns the binding's value from 0-1
|
||||
float value() const;
|
||||
|
||||
// returns the bindings signed value (0 or 1)
|
||||
int sign() const;
|
||||
|
||||
// returns the timestamp of the last time the binding was pressed
|
||||
double timestamp() const;
|
||||
|
||||
// updates the binding state
|
||||
void update();
|
||||
|
||||
// consumes the current press, and pressed() will return false until the next press
|
||||
void consume_press();
|
||||
|
||||
// consumes the current release, and released() will return false until the next release
|
||||
void consume_release();
|
||||
|
||||
// adds a key to the binding
|
||||
InputBinding& add(Key key);
|
||||
|
||||
// adds a button to the binding
|
||||
InputBinding& add(ButtonBind button);
|
||||
|
||||
// adds an trigger to the binding
|
||||
InputBinding& add(TriggerBind trigger);
|
||||
|
||||
// adds a mouse button to the binding
|
||||
InputBinding& add(MouseButton mouse);
|
||||
|
||||
// adds an input to the binding
|
||||
template<typename T, typename T2, typename ... Args>
|
||||
InputBinding& add(T first, T2 second, const Args&... args)
|
||||
{
|
||||
add(first);
|
||||
add(second, args...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// adds the left trigger to the binding
|
||||
InputBinding& add_left_trigger(int controller, float threshold);
|
||||
|
||||
// adds the right trigger to the binding
|
||||
InputBinding& add_right_trigger(int controller, float threshold);
|
||||
|
||||
// assigns all the bindings to the specific controller
|
||||
InputBinding& set_controller(int index);
|
||||
|
||||
// removes all bindings
|
||||
void clear();
|
||||
|
||||
private:
|
||||
double m_last_timestamp = 0;
|
||||
double m_last_press_time = -1;
|
||||
double m_last_release_time = -1;
|
||||
float m_value = 0.0f;
|
||||
bool m_pressed = false;
|
||||
bool m_released = false;
|
||||
bool m_down = false;
|
||||
bool m_press_consumed = false;
|
||||
bool m_release_consumed = false;
|
||||
|
||||
bool get_pressed() const;
|
||||
bool get_released() const;
|
||||
bool get_down() const;
|
||||
float get_value() const;
|
||||
};
|
||||
|
||||
// Axis Binding (ex. Left/Right movement, or a Trigger)
|
||||
// You must call AxisBinding::update() every frame to poll the input state.
|
||||
// Alternatively, bindings can be registered to Input which will
|
||||
// automatically update them.
|
||||
class AxisBinding
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Overlap
|
||||
{
|
||||
Newer,
|
||||
Older,
|
||||
Cancel
|
||||
};
|
||||
|
||||
// Negative Value Binding
|
||||
InputBinding negative;
|
||||
|
||||
// Positive Value Binding
|
||||
InputBinding positive;
|
||||
|
||||
// How to handle overlaps (ex. Left and Right are both held)
|
||||
Overlap overlap = Overlap::Newer;
|
||||
|
||||
AxisBinding() = default;
|
||||
|
||||
AxisBinding(const InputBinding& negative, const InputBinding& positive, Overlap overlap = Overlap::Newer)
|
||||
: negative(negative)
|
||||
, positive(positive)
|
||||
, overlap(overlap)
|
||||
{}
|
||||
|
||||
// Current Value from -1 to 1
|
||||
float value() const;
|
||||
|
||||
// Current value, either -1, 0, or 1
|
||||
int sign() const;
|
||||
|
||||
// updates the Binding
|
||||
void update();
|
||||
|
||||
// consumes the press buffer
|
||||
void consume_press();
|
||||
|
||||
// consumes the release buffer
|
||||
void consume_release();
|
||||
|
||||
// Adds a negative & positive binding pair
|
||||
template<typename NegativeT, typename PositiveT>
|
||||
AxisBinding& add(NegativeT negative, PositiveT positive)
|
||||
{
|
||||
this->negative.add(negative);
|
||||
this->positive.add(positive);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Adds a Stick binding
|
||||
AxisBinding& add_left_stick_x(int controller, float threshold);
|
||||
AxisBinding& add_left_stick_y(int controller, float threshold);
|
||||
AxisBinding& add_right_stick_x(int controller, float threshold);
|
||||
AxisBinding& add_right_stick_y(int controller, float threshold);
|
||||
|
||||
// assigns all the bindings to the specific controller
|
||||
AxisBinding& set_controller(int index);
|
||||
|
||||
// Clears all Bindings
|
||||
void clear();
|
||||
};
|
||||
|
||||
// Stick Binding (ex. Joystick, Dpad, Arrow Keys, WASD, etc)
|
||||
// You must call StickBinding::update() every frame to poll the input state.
|
||||
// Alternatively, bindings can be registered to Input which will
|
||||
// automatically update them.
|
||||
class StickBinding
|
||||
{
|
||||
public:
|
||||
|
||||
// X Axis Binding
|
||||
AxisBinding x;
|
||||
|
||||
// Y Axis Binding
|
||||
AxisBinding y;
|
||||
|
||||
// An optional threshold for circular thresholds
|
||||
float round_threshold = 0.0f;
|
||||
|
||||
StickBinding() = default;
|
||||
|
||||
StickBinding(const AxisBinding& x, const AxisBinding& y, float round_threshold = 0)
|
||||
: x(x)
|
||||
, y(y)
|
||||
, round_threshold(round_threshold)
|
||||
{}
|
||||
|
||||
// Current Value, -1 to 1
|
||||
Vec2 value() const;
|
||||
|
||||
// Current value, either -1, 0, or 1
|
||||
Point sign() const;
|
||||
|
||||
// Updates the Binding
|
||||
void update();
|
||||
|
||||
// Consumes the Press Buffer
|
||||
void consume_press();
|
||||
|
||||
// Consumes the Release Buffer
|
||||
void consume_release();
|
||||
|
||||
// Adds directional bindings
|
||||
template<typename LeftT, typename RightT, typename UpT, typename DownT>
|
||||
StickBinding& add(LeftT left, RightT right, UpT up, DownT down)
|
||||
{
|
||||
x.negative.add(left);
|
||||
x.positive.add(right);
|
||||
y.negative.add(up);
|
||||
y.positive.add(down);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Adds the dpad binding
|
||||
StickBinding& add_dpad(int controller);
|
||||
|
||||
// Adds the left stick binding
|
||||
StickBinding& add_left_stick(int controller, float threshold);
|
||||
|
||||
// Adds the right stick binding
|
||||
StickBinding& add_right_stick(int controller, float threshold);
|
||||
|
||||
// assigns all the bindings to the specific controller
|
||||
StickBinding& set_controller(int index);
|
||||
|
||||
// Clears all the bindings
|
||||
void clear();
|
||||
};
|
||||
|
||||
namespace Input
|
||||
{
|
||||
// Returns the Input State of the current frame.
|
||||
@ -427,5 +728,14 @@ namespace Blah
|
||||
|
||||
// returns a string name of the given button
|
||||
const char* name_of(Button button);
|
||||
|
||||
// registers a new binding
|
||||
InputBindingRef register_binding(const InputBinding& binding);
|
||||
|
||||
// registers a new axis binding
|
||||
AxisBindingRef register_binding(const AxisBinding& binding);
|
||||
|
||||
// registers a new stick binding
|
||||
StickBindingRef register_binding(const StickBinding& binding);
|
||||
}
|
||||
}
|
@ -1,299 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/input/input.h>
|
||||
#include <blah/containers/stackvector.h>
|
||||
#include <blah/math/point.h>
|
||||
#include <blah/math/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
// Single input Binding
|
||||
// You must call Binding::update() every frame to poll the input state.
|
||||
// Alternatively, bindings can be registered to BindingRegistry which will
|
||||
// automatically update them.
|
||||
class Binding
|
||||
{
|
||||
public:
|
||||
|
||||
// Represents a Controller Trigger or a single direction of a Controller Axis.
|
||||
struct TriggerBind
|
||||
{
|
||||
// Controller Index we're bound to
|
||||
int controller = 0;
|
||||
|
||||
// The Axis we're bound to
|
||||
Axis axis = Axis::None;
|
||||
|
||||
// Minimum value of the axis
|
||||
float threshold = 0.01f;
|
||||
|
||||
// requires a positive value
|
||||
// otherwise requires a negative value
|
||||
bool positive = true;
|
||||
|
||||
TriggerBind() = default;
|
||||
TriggerBind(Axis axis);
|
||||
TriggerBind(int controller, Axis axis, float threshold, bool positive);
|
||||
|
||||
bool is_down(float axis_value) const;
|
||||
};
|
||||
|
||||
// Represents a Controller Button.
|
||||
struct ButtonBind
|
||||
{
|
||||
// Controller Index we're bound to
|
||||
int controller = 0;
|
||||
|
||||
// Button we're bound to
|
||||
Button button = Button::None;
|
||||
|
||||
ButtonBind() = default;
|
||||
ButtonBind(Button button);
|
||||
ButtonBind(int controller, Button button);
|
||||
};
|
||||
|
||||
// Input Buffer for press events
|
||||
float press_buffer = 0;
|
||||
|
||||
// Input Buffer for release events
|
||||
float release_buffer = 0;
|
||||
|
||||
// List of bound Keys
|
||||
StackVector<Key, 16> keys;
|
||||
|
||||
// List of bound Buttons
|
||||
StackVector<ButtonBind, 16> buttons;
|
||||
|
||||
// List of bound Triggers / Axis
|
||||
StackVector<TriggerBind, 16> triggers;
|
||||
|
||||
// List of bound Mouse buttons
|
||||
StackVector<MouseButton, 16> mouse;
|
||||
|
||||
Binding() = default;
|
||||
|
||||
Binding(float press_buffer)
|
||||
: press_buffer(press_buffer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
Binding(float press_buffer, const Args&... args)
|
||||
: press_buffer(press_buffer)
|
||||
{
|
||||
add(args...);
|
||||
}
|
||||
|
||||
// if the binding has been pressed
|
||||
bool pressed() const;
|
||||
|
||||
// if the binding has been released
|
||||
bool released() const;
|
||||
|
||||
// if the binding is currently held
|
||||
bool down() const;
|
||||
|
||||
// returns the binding's value from 0-1
|
||||
float value() const;
|
||||
|
||||
// returns the bindings signed value (0 or 1)
|
||||
int sign() const;
|
||||
|
||||
// returns the timestamp of the last time the binding was pressed
|
||||
double timestamp() const;
|
||||
|
||||
// updates the binding state
|
||||
void update();
|
||||
|
||||
// consumes the current press, and pressed() will return false until the next press
|
||||
void consume_press();
|
||||
|
||||
// consumes the current release, and released() will return false until the next release
|
||||
void consume_release();
|
||||
|
||||
// adds a key to the binding
|
||||
Binding& add(Key key);
|
||||
|
||||
// adds a button to the binding
|
||||
Binding& add(ButtonBind button);
|
||||
|
||||
// adds an trigger to the binding
|
||||
Binding& add(TriggerBind trigger);
|
||||
|
||||
// adds a mouse button to the binding
|
||||
Binding& add(MouseButton mouse);
|
||||
|
||||
// adds an input to the binding
|
||||
template<typename T, typename T2, typename ... Args>
|
||||
Binding& add(T first, T2 second, const Args&... args)
|
||||
{
|
||||
add(first);
|
||||
add(second, args...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// adds the left trigger to the binding
|
||||
Binding& add_left_trigger(int controller, float threshold);
|
||||
|
||||
// adds the right trigger to the binding
|
||||
Binding& add_right_trigger(int controller, float threshold);
|
||||
|
||||
// assigns all the bindings to the specific controller
|
||||
Binding& set_controller(int index);
|
||||
|
||||
// removes all bindings
|
||||
void clear();
|
||||
|
||||
private:
|
||||
double m_last_timestamp = 0;
|
||||
double m_last_press_time = -1;
|
||||
double m_last_release_time = -1;
|
||||
float m_value = 0.0f;
|
||||
bool m_pressed = false;
|
||||
bool m_released = false;
|
||||
bool m_down = false;
|
||||
bool m_press_consumed = false;
|
||||
bool m_release_consumed = false;
|
||||
|
||||
bool get_pressed() const;
|
||||
bool get_released() const;
|
||||
bool get_down() const;
|
||||
float get_value() const;
|
||||
};
|
||||
|
||||
// Axis Binding (ex. Left/Right movement, or a Trigger)
|
||||
// You must call AxisBinding::update() every frame to poll the input state.
|
||||
// Alternatively, bindings can be registered to BindingRegistry which will
|
||||
// automatically update them.
|
||||
class AxisBinding
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Overlap
|
||||
{
|
||||
Newer,
|
||||
Older,
|
||||
Cancel
|
||||
};
|
||||
|
||||
// Negative Value Binding
|
||||
Binding negative;
|
||||
|
||||
// Positive Value Binding
|
||||
Binding positive;
|
||||
|
||||
// How to handle overlaps (ex. Left and Right are both held)
|
||||
Overlap overlap = Overlap::Newer;
|
||||
|
||||
AxisBinding() = default;
|
||||
|
||||
AxisBinding(const Binding& negative, const Binding& positive, Overlap overlap = Overlap::Newer)
|
||||
: negative(negative)
|
||||
, positive(positive)
|
||||
, overlap(overlap)
|
||||
{}
|
||||
|
||||
// Current Value from -1 to 1
|
||||
float value() const;
|
||||
|
||||
// Current value, either -1, 0, or 1
|
||||
int sign() const;
|
||||
|
||||
// updates the Binding
|
||||
void update();
|
||||
|
||||
// consumes the press buffer
|
||||
void consume_press();
|
||||
|
||||
// consumes the release buffer
|
||||
void consume_release();
|
||||
|
||||
// Adds a negative & positive binding pair
|
||||
template<typename NegativeT, typename PositiveT>
|
||||
AxisBinding& add(NegativeT negative, PositiveT positive)
|
||||
{
|
||||
this->negative.add(negative);
|
||||
this->positive.add(positive);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Adds a Stick binding
|
||||
AxisBinding& add_left_stick_x(int controller, float threshold);
|
||||
AxisBinding& add_left_stick_y(int controller, float threshold);
|
||||
AxisBinding& add_right_stick_x(int controller, float threshold);
|
||||
AxisBinding& add_right_stick_y(int controller, float threshold);
|
||||
|
||||
// assigns all the bindings to the specific controller
|
||||
AxisBinding& set_controller(int index);
|
||||
|
||||
// Clears all Bindings
|
||||
void clear();
|
||||
};
|
||||
|
||||
// Stick Binding (ex. Joystick, Dpad, Arrow Keys, WASD, etc)
|
||||
// You must call StickBinding::update() every frame to poll the input state.
|
||||
// Alternatively, bindings can be registered to BindingRegistry which will
|
||||
// automatically update them.
|
||||
class StickBinding
|
||||
{
|
||||
public:
|
||||
|
||||
// X Axis Binding
|
||||
AxisBinding x;
|
||||
|
||||
// Y Axis Binding
|
||||
AxisBinding y;
|
||||
|
||||
// An optional threshold for circular thresholds
|
||||
float round_threshold = 0.0f;
|
||||
|
||||
StickBinding() = default;
|
||||
|
||||
StickBinding(const AxisBinding& x, const AxisBinding& y, float round_threshold = 0)
|
||||
: x(x)
|
||||
, y(y)
|
||||
, round_threshold(round_threshold)
|
||||
{}
|
||||
|
||||
// Current Value, -1 to 1
|
||||
Vec2 value() const;
|
||||
|
||||
// Current value, either -1, 0, or 1
|
||||
Point sign() const;
|
||||
|
||||
// Updates the Binding
|
||||
void update();
|
||||
|
||||
// Consumes the Press Buffer
|
||||
void consume_press();
|
||||
|
||||
// Consumes the Release Buffer
|
||||
void consume_release();
|
||||
|
||||
// Adds directional bindings
|
||||
template<typename LeftT, typename RightT, typename UpT, typename DownT>
|
||||
StickBinding& add(LeftT left, RightT right, UpT up, DownT down)
|
||||
{
|
||||
x.negative.add(left);
|
||||
x.positive.add(right);
|
||||
y.negative.add(up);
|
||||
y.positive.add(down);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Adds the dpad binding
|
||||
StickBinding& add_dpad(int controller);
|
||||
|
||||
// Adds the left stick binding
|
||||
StickBinding& add_left_stick(int controller, float threshold);
|
||||
|
||||
// Adds the right stick binding
|
||||
StickBinding& add_right_stick(int controller, float threshold);
|
||||
|
||||
// assigns all the bindings to the specific controller
|
||||
StickBinding& set_controller(int index);
|
||||
|
||||
// Clears all the bindings
|
||||
void clear();
|
||||
};
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/input/binding.h>
|
||||
#include <blah/containers/vector.h>
|
||||
#include <memory>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
using BindingRef = std::shared_ptr<Binding>;
|
||||
using AxisBindingRef = std::shared_ptr<AxisBinding>;
|
||||
using StickBindingRef = std::shared_ptr<StickBinding>;
|
||||
|
||||
// An Optional registry to automatically update Input Bindings.
|
||||
// Once registered here, you do not need to explicitely call their update methods.
|
||||
class BindingRegistry
|
||||
{
|
||||
public:
|
||||
// registers a new binding
|
||||
static BindingRef register_binding(const Binding& binding = Binding());
|
||||
|
||||
// registers a new axis binding
|
||||
static AxisBindingRef register_axis(const AxisBinding& binding = AxisBinding());
|
||||
|
||||
// registers a new stick binding
|
||||
static StickBindingRef register_stick(const StickBinding& binding = StickBinding());
|
||||
|
||||
// updates all the bindings. This is called
|
||||
// automatically by the App loop.
|
||||
static void update();
|
||||
|
||||
private:
|
||||
static Vector<std::weak_ptr<Binding>> bindings;
|
||||
static Vector<std::weak_ptr<AxisBinding>> axes;
|
||||
static Vector<std::weak_ptr<StickBinding>> sticks;
|
||||
};
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
class Stopwatch
|
||||
{
|
||||
public:
|
||||
Stopwatch();
|
||||
void reset();
|
||||
u64 microseconds();
|
||||
u64 milliseconds();
|
||||
private:
|
||||
u64 start_time;
|
||||
};
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/str.h>
|
||||
|
||||
namespace Blah
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/math/calc.h>
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/numerics/calc.h>
|
||||
#include <blah/common.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -289,7 +289,7 @@ namespace Blah
|
||||
break;
|
||||
}
|
||||
|
||||
BLAH_ERROR("Invalid Easer Type");
|
||||
BLAH_ASSERT(false, "Invalid Easer Type");
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include <blah/math/point.h>
|
||||
#include <blah/math/vec2.h>
|
||||
#include <blah/math/rectI.h>
|
||||
#include <blah/math/line.h>
|
||||
#include <blah/numerics/point.h>
|
||||
#include <blah/numerics/vec2.h>
|
||||
#include <blah/numerics/rectI.h>
|
||||
#include <blah/numerics/line.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/math/point.h>
|
||||
#include <blah/numerics/point.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
@ -12,28 +12,28 @@ namespace Blah
|
||||
BufferStream& operator=(BufferStream&& bs) noexcept;
|
||||
~BufferStream();
|
||||
|
||||
virtual i64 length() const override { return m_length; }
|
||||
virtual i64 position() const override { return m_position; }
|
||||
virtual i64 seek(i64 seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
|
||||
virtual size_t length() const override { return m_length; }
|
||||
virtual size_t position() const override { return m_position; }
|
||||
virtual size_t seek(size_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
|
||||
virtual bool is_open() const override { return m_buffer != nullptr; }
|
||||
virtual bool is_readable() const override { return true; }
|
||||
virtual bool is_writable() const override { return true; }
|
||||
virtual void close() override;
|
||||
|
||||
void resize(i64 length);
|
||||
void resize(size_t length);
|
||||
void clear() { m_length = m_position = 0; }
|
||||
|
||||
char* data() { return m_buffer; }
|
||||
const char* data() const { return m_buffer; }
|
||||
|
||||
protected:
|
||||
virtual i64 read_into(void* ptr, i64 length) override;
|
||||
virtual i64 write_from(const void* ptr, i64 length) override;
|
||||
virtual size_t read_into(void* ptr, size_t length) override;
|
||||
virtual size_t write_from(const void* ptr, size_t length) override;
|
||||
|
||||
private:
|
||||
char* m_buffer;
|
||||
i64 m_capacity;
|
||||
i64 m_length;
|
||||
i64 m_position;
|
||||
size_t m_capacity;
|
||||
size_t m_length;
|
||||
size_t m_position;
|
||||
};
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <blah/streams/stream.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/filesystem.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -11,22 +11,21 @@ namespace Blah
|
||||
FileStream(const FilePath& path, FileMode mode);
|
||||
FileStream(FileStream&& fs) noexcept;
|
||||
FileStream& operator=(FileStream&& fs) noexcept;
|
||||
~FileStream();
|
||||
|
||||
i64 length() const override;
|
||||
i64 position() const override;
|
||||
i64 seek(i64 seekTo) override;
|
||||
size_t length() const override;
|
||||
size_t position() const override;
|
||||
size_t seek(size_t position) override;
|
||||
bool is_open() const override;
|
||||
bool is_readable() const override;
|
||||
bool is_writable() const override;
|
||||
void close() override;
|
||||
|
||||
protected:
|
||||
i64 read_into(void* ptr, i64 length) override;
|
||||
i64 write_from(const void* ptr, i64 length) override;
|
||||
size_t read_into(void* ptr, size_t length) override;
|
||||
size_t write_from(const void* ptr, size_t length) override;
|
||||
|
||||
private:
|
||||
FileMode m_mode;
|
||||
void* m_handle;
|
||||
FileRef m_file;
|
||||
};
|
||||
}
|
@ -7,14 +7,14 @@ namespace Blah
|
||||
{
|
||||
public:
|
||||
MemoryStream();
|
||||
MemoryStream(char* data, i64 length);
|
||||
MemoryStream(char* data, size_t length);
|
||||
MemoryStream(MemoryStream&& ms) noexcept;
|
||||
MemoryStream& operator=(MemoryStream&& ms) noexcept;
|
||||
~MemoryStream() override { m_data = nullptr; m_length = m_position = 0; }
|
||||
|
||||
i64 length() const override { return m_length; }
|
||||
i64 position() const override { return m_position; }
|
||||
i64 seek(i64 seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
|
||||
size_t length() const override { return m_length; }
|
||||
size_t position() const override { return m_position; }
|
||||
size_t seek(size_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
|
||||
bool is_open() const override { return m_data != nullptr; }
|
||||
bool is_readable() const override { return true; }
|
||||
bool is_writable() const override { return true; }
|
||||
@ -24,12 +24,12 @@ namespace Blah
|
||||
const char* data() const { return m_data; }
|
||||
|
||||
protected:
|
||||
i64 read_into(void* ptr, i64 length) override;
|
||||
i64 write_from(const void* ptr, i64 length) override;
|
||||
size_t read_into(void* ptr, size_t length) override;
|
||||
size_t write_from(const void* ptr, size_t length) override;
|
||||
|
||||
private:
|
||||
char* m_data;
|
||||
i64 m_length;
|
||||
i64 m_position;
|
||||
size_t m_length;
|
||||
size_t m_position;
|
||||
};
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
#include <blah/containers/str.h>
|
||||
#include <blah/streams/endian.h>
|
||||
#include <string.h>
|
||||
@ -16,13 +16,13 @@ namespace Blah
|
||||
virtual ~Stream() = default;
|
||||
|
||||
// returns the length of the stream
|
||||
virtual i64 length() const = 0;
|
||||
virtual size_t length() const = 0;
|
||||
|
||||
// returns the position of the stream
|
||||
virtual i64 position() const = 0;
|
||||
virtual size_t position() const = 0;
|
||||
|
||||
// seeks the position of the stream
|
||||
virtual i64 seek(i64 seek_to) = 0;
|
||||
virtual size_t seek(size_t position) = 0;
|
||||
|
||||
// returns true of the stream is open
|
||||
virtual bool is_open() const = 0;
|
||||
@ -37,10 +37,10 @@ namespace Blah
|
||||
virtual void close() = 0;
|
||||
|
||||
// pipes the contents of this stream to another stream
|
||||
i64 pipe(Stream& to, i64 length);
|
||||
size_t pipe(Stream& to, size_t length);
|
||||
|
||||
// reads the amount of bytes into the given buffer, and returns the amount read
|
||||
i64 read(void* buffer, i64 length) { return read_into(buffer, length); }
|
||||
size_t read(void* buffer, size_t length) { return read_into(buffer, length); }
|
||||
|
||||
// reads a string. if length < 0, assumes null-terminated
|
||||
String read_string(int length = -1);
|
||||
@ -67,21 +67,21 @@ namespace Blah
|
||||
}
|
||||
|
||||
// writes the amount of bytes to the stream from the given buffer, and returns the amount written
|
||||
i64 write(const void* buffer, i64 length);
|
||||
size_t write(const void* buffer, size_t length);
|
||||
|
||||
// writes the contents of a string to the stream
|
||||
i64 write(const String& string);
|
||||
size_t write(const String& string);
|
||||
|
||||
// writes a number
|
||||
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
|
||||
i64 write(const T& value)
|
||||
size_t write(const T& value)
|
||||
{
|
||||
return write<T>(value, Endian::Little);
|
||||
}
|
||||
|
||||
// writes a number
|
||||
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
|
||||
i64 write(const T& value, Endian endian)
|
||||
size_t write(const T& value, Endian endian)
|
||||
{
|
||||
T writing = value;
|
||||
|
||||
@ -93,9 +93,9 @@ namespace Blah
|
||||
|
||||
protected:
|
||||
// reads from the stream into the given buffer, and returns the number of bytes read
|
||||
virtual i64 read_into(void* buffer, i64 length) = 0;
|
||||
virtual size_t read_into(void* buffer, size_t length) = 0;
|
||||
|
||||
// writes from the stream from the given buffer, and returns the number of bytes written
|
||||
virtual i64 write_from(const void* buffer, i64 length) = 0;
|
||||
virtual size_t write_from(const void* buffer, size_t length) = 0;
|
||||
};
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <blah/core/common.h>
|
||||
#include <blah/common.h>
|
||||
|
||||
namespace Blah
|
||||
{
|
||||
@ -47,4 +47,16 @@ namespace Blah
|
||||
// returns true between time intervals
|
||||
static bool between_interval(float interval, float offset = 0);
|
||||
};
|
||||
|
||||
class Stopwatch
|
||||
{
|
||||
public:
|
||||
Stopwatch();
|
||||
void reset();
|
||||
u64 microseconds();
|
||||
u64 milliseconds();
|
||||
|
||||
private:
|
||||
u64 start_time;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user