replaced log.h with common.h, added easier shorthand for int types

This commit is contained in:
Noel Berry 2021-03-20 17:33:04 -07:00
parent 9f9ed08007
commit d73241e8fe
58 changed files with 416 additions and 408 deletions

View File

@ -2,7 +2,7 @@
#include "blah/core/app.h"
#include "blah/core/filesystem.h"
#include "blah/core/log.h"
#include "blah/core/common.h"
#include "blah/core/time.h"
#include "blah/containers/vector.h"

View File

@ -1,5 +1,5 @@
#pragma once
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <new>
#include <initializer_list>

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <stdarg.h>
#include <cstdio>
#include <blah/containers/vector.h>
@ -78,7 +78,7 @@ namespace Blah
// Returns the unicode value at the given index.
// Assumes the index is a valid utf8 starting point.
uint32_t utf8_at(int index) const;
u32 utf8_at(int index) const;
// Returns the byte-length of the utf8 character.
// Assumes the index is a valid utf8 starting point.
@ -88,7 +88,7 @@ namespace Blah
Str& append(char c);
// appends the given unicode character
Str& append(uint32_t c);
Str& append(u32 c);
// appends the given c string
Str& append(const char* start, const char* end = nullptr);
@ -100,7 +100,7 @@ namespace Blah
Str& append_fmt(const char* fmt, ...);
// appends a utf16 string
Str& append_utf16(const uint16_t* start, const uint16_t* end = nullptr, bool swapEndian = false);
Str& append_utf16(const u16* start, const u16* end = nullptr, bool swapEndian = false);
// trims whitespace
Str& trim();

View File

@ -1,5 +1,5 @@
#pragma once
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <type_traits>
#include <new>

View File

@ -1,7 +1,7 @@
#pragma once
#include <memory>
#include <functional>
#include <blah/core/log.h>
#include <blah/core/common.h>
namespace Blah
{

View File

@ -1,21 +1,22 @@
#pragma once
#include <cstdint>
// error / abort
#if defined(DEBUG) || defined(_DEBUG)
#include <stdlib.h>
#define BLAH_ERROR(message) \
#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, ...) \
#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) \
#define BLAH_ERROR(message) \
Blah::Log::error(message "\n\tin file: %s:%d", __FILE__, __LINE__)
#define BLAH_ERROR_FMT(message, ...) \
#define BLAH_ERROR_FMT(message, ...) \
Blah::Log::error(message "\n\tin file: %s:%d", __VA_ARGS__, __FILE__, __LINE__)
#endif
@ -33,6 +34,16 @@
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
@ -42,8 +53,8 @@ namespace Blah
Error
};
void print(const char* info, ...);
void warn(const char* info, ...);
void error(const char* info, ...);
void info(const char* message, ...);
void warn(const char* message, ...);
void error(const char* message, ...);
}
}

View File

@ -1,21 +1,21 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
namespace Blah
{
struct Time
{
// ticks per second (microseconds, in this case)
static constexpr uint64_t ticks_per_second = 1000000;
static constexpr u64 ticks_per_second = 1000000;
// uptime, in ticks
static uint64_t ticks;
static u64 ticks;
// uptime, in seconds
static double seconds;
// previous frame uptime, in ticks
static uint64_t previous_ticks;
static u64 previous_ticks;
// previous frame uptime, in seconds
static double previous_seconds;

View File

@ -187,10 +187,10 @@ namespace Blah
Vec2 tex;
Color col;
uint8_t mult;
uint8_t wash;
uint8_t fill;
uint8_t pad;
u8 mult;
u8 wash;
u8 fill;
u8 pad;
};
struct DrawBatch
@ -219,11 +219,11 @@ namespace Blah
MeshRef m_mesh;
Mat3x2 m_matrix;
ColorMode m_color_mode;
uint8_t m_tex_mult;
uint8_t m_tex_wash;
u8 m_tex_mult;
u8 m_tex_wash;
DrawBatch m_batch;
Vector<Vertex> m_vertices;
Vector<uint32_t> m_indices;
Vector<u32> m_indices;
Vector<Mat3x2> m_matrix_stack;
Vector<Rect> m_scissor_stack;
Vector<BlendMode> m_blend_stack;

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/containers/str.h>
#include <blah/containers/vector.h>
#include <blah/drawing/subtexture.h>
@ -21,14 +21,14 @@ namespace Blah
};
private:
// charset & kerning maps
std::unordered_map<uint32_t, Character> m_characters;
std::unordered_map<uint64_t, float> m_kerning;
std::unordered_map<u32, Character> m_characters;
std::unordered_map<u64, float> m_kerning;
// built texture
Vector<TextureRef> m_atlas;
public:
static const uint32_t* ASCII;
static const u32* ASCII;
String name;
float size;
@ -41,9 +41,9 @@ namespace Blah
SpriteFont();
SpriteFont(const char* file, float size);
SpriteFont(const char* file, float size, const uint32_t* charset);
SpriteFont(const char* file, float size, const u32* charset);
SpriteFont(const Font& font, float size);
SpriteFont(const Font& font, float size, const uint32_t* charset);
SpriteFont(const Font& font, float size, const u32* charset);
SpriteFont(const SpriteFont&) = delete;
SpriteFont(SpriteFont&& src) noexcept;
~SpriteFont();
@ -62,15 +62,15 @@ namespace Blah
float width_of_line(const String& text, int start = 0) const;
float height_of(const String& text) const;
void build(const char* file, float size, const uint32_t* charset);
void build(const Font& font, float size, const uint32_t* charset);
void build(const char* file, float size, const u32* charset);
void build(const Font& font, float size, const u32* charset);
float get_kerning(uint32_t codepoint0, uint32_t codepoint1) const;
void set_kerning(uint32_t codepoint0, uint32_t codepoint1, float kerning);
float get_kerning(u32 codepoint0, u32 codepoint1) const;
void set_kerning(u32 codepoint0, u32 codepoint1, float kerning);
Character& get_character(uint32_t codepoint) { return m_characters[codepoint]; }
const Character& get_character(uint32_t codepoint) const;
Character& operator[](uint32_t codepoint) { return m_characters[codepoint]; }
const Character& operator[](uint32_t codepoint) const;
Character& get_character(u32 codepoint) { return m_characters[codepoint]; }
const Character& get_character(u32 codepoint) const;
Character& operator[](u32 codepoint) { return m_characters[codepoint]; }
const Character& operator[](u32 codepoint) const;
};
}

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
namespace Blah
{
@ -61,7 +61,7 @@ namespace Blah
BlendFactor alpha_src;
BlendFactor alpha_dst;
BlendMask mask;
uint32_t rgba;
u32 rgba;
BlendMode() = default;
@ -78,7 +78,7 @@ namespace Blah
BlendMode(
BlendOp color_op, BlendFactor color_src, BlendFactor color_dst,
BlendOp alpha_op, BlendFactor alpha_src, BlendFactor alpha_dst,
BlendMask blend_mask, uint32_t blend_rgba) :
BlendMask blend_mask, u32 blend_rgba) :
color_op(color_op),
color_src(color_src),
color_dst(color_dst),

View File

@ -65,7 +65,7 @@ namespace Blah
virtual int height() const = 0;
// Clears the FrameBuffer
virtual void clear(Color color = Color::black, float depth = 1.0f, uint8_t stencil = 0, ClearMask mask = ClearMask::All) = 0;
virtual void clear(Color color = Color::black, float depth = 1.0f, u8 stencil = 0, ClearMask mask = ClearMask::All) = 0;
};
}

View File

@ -59,10 +59,10 @@ namespace Blah
// Sets the value. `length` is the total number of floats to set
// For example if the uniform is a float2[4], a total of 8 float values
// can be set.
void set_value(const char* name, const float* value, int64_t length);
void set_value(const char* name, const float* value, i64 length);
// Gets a pointer to the values of the given Uniform, or nullptr if it doesn't exist.
const float* get_value(const char* name, int64_t* length = nullptr) const;
const float* get_value(const char* name, i64* length = nullptr) const;
// Returns the internal Texture buffer
const Vector<TextureRef>& textures() const;

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <memory>
#include <blah/containers/stackvector.h>
@ -73,21 +73,21 @@ namespace Blah
static MeshRef create();
// Uploads the given index buffer to the Mesh
virtual void index_data(IndexFormat format, const void* indices, int64_t count) = 0;
virtual void index_data(IndexFormat format, const void* indices, i64 count) = 0;
// Uploads the given vertex buffer to the Mesh
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) = 0;
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) = 0;
// Uploads the given instance buffer to the Mesh
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) = 0;
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) = 0;
// Gets the index count of the Mesh
virtual int64_t index_count() const = 0;
virtual i64 index_count() const = 0;
// Gets the vertex count of the Mesh
virtual int64_t vertex_count() const = 0;
virtual i64 vertex_count() const = 0;
// Gets the instance count of the Mesh
virtual int64_t instance_count() const = 0;
virtual i64 instance_count() const = 0;
};
}

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/math/rect.h>
#include <blah/containers/str.h>
#include <blah/graphics/texture.h>
@ -55,13 +55,13 @@ namespace Blah
Rect scissor;
// First index in the Mesh to draw from
int64_t index_start;
i64 index_start;
// Total amount of indices to draw from the Mesh
int64_t index_count;
i64 index_count;
// Total amount of instances to draw from the Mesh
int64_t instance_count;
i64 instance_count;
// Depth Compare Function
Compare depth;

View File

@ -5,7 +5,7 @@
namespace Blah
{
typedef uint32_t Codepoint;
typedef u32 Codepoint;
class Font
{

View File

@ -18,15 +18,15 @@ namespace Blah
{
friend class Packer;
private:
int64_t memory_index;
i64 memory_index;
public:
uint64_t id;
u64 id;
int page;
bool empty;
RectI frame;
RectI packed;
Entry(uint64_t id, const RectI& frame)
Entry(u64 id, const RectI& frame)
: memory_index(0), id(id), page(0), empty(true), frame(frame), packed(0, 0, 0, 0) {}
};
@ -46,9 +46,9 @@ namespace Blah
Packer& operator=(Packer&& src) noexcept;
~Packer();
void add(uint64_t id, int width, int height, const Color* pixels);
void add(uint64_t id, const Image& bitmap);
void add(uint64_t id, const String& path);
void add(u64 id, int width, int height, const Color* pixels);
void add(u64 id, const Image& bitmap);
void add(u64 id, const String& path);
void pack();
void clear();
@ -70,6 +70,6 @@ namespace Blah
bool m_dirty;
BufferStream m_buffer;
void add_entry(uint64_t id, int w, int h, const Color* pixels);
void add_entry(u64 id, int w, int h, const Color* pixels);
};
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/math/vec2.h>
// These are generally copied from the SDL2 Scancode Keys
@ -293,19 +293,19 @@ namespace Blah
float axis[Input::max_controller_axis];
// Timestamp, in milliseconds, since each button was last pressed
uint64_t button_timestamp[Input::max_controller_buttons];
u64 button_timestamp[Input::max_controller_buttons];
// Timestamp, in milliseconds, since each axis last had a value set
uint64_t axis_timestamp[Input::max_controller_axis];
u64 axis_timestamp[Input::max_controller_axis];
// The USB Vendor ID
uint16_t vendor;
u16 vendor;
// The USB Product ID
uint16_t product;
u16 product;
// the Product Version
uint16_t version;
u16 version;
};
struct KeyboardState
@ -313,7 +313,7 @@ namespace Blah
bool pressed[Input::max_keyboard_keys];
bool down[Input::max_keyboard_keys];
bool released[Input::max_keyboard_keys];
uint64_t timestamp[Input::max_keyboard_keys];
u64 timestamp[Input::max_keyboard_keys];
char text[Input::max_text_input];
};
@ -322,7 +322,7 @@ namespace Blah
bool pressed[Input::max_mouse_buttons];
bool down[Input::max_mouse_buttons];
bool released[Input::max_mouse_buttons];
uint64_t timestamp[Input::max_mouse_buttons];
u64 timestamp[Input::max_mouse_buttons];
Vec2 screen_position;
Vec2 draw_position;
Vec2 position;

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/math/vec2.h>
namespace Blah
@ -27,10 +27,6 @@ namespace Blah
Vec2 approach(const Vec2& t, const Vec2& target, float delta);
float clamp(float t, float min, float max);
int clamp_int(int t, int min, int max);
float map(float t, float old_min, float old_max, float new_min, float new_max);
float clamped_map(float t, float old_min, float old_max, float new_min, float new_max);
@ -43,6 +39,9 @@ namespace Blah
float abs(float x);
template<class T>
T clamp(T value, T min, T max) { return value < min ? min : (value > max ? max : value); }
template<class T, class U>
T min(T a, U b) { return (T)(a < b ? a : b); }

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/containers/str.h>
namespace Blah
@ -8,16 +8,16 @@ namespace Blah
struct Color
{
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
u8 r;
u8 g;
u8 b;
u8 a;
Color();
Color(int rgb);
Color(int rgb, float alpha);
Color(uint8_t r, uint8_t g, uint8_t b);
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
Color(u8 r, u8 g, u8 b);
Color(u8 r, u8 g, u8 b, u8 a);
Color(const Vec4& vec4);
// Parses a Hex string in the format of "#00000000" or "0x00000000" or "00000000"
@ -40,17 +40,17 @@ namespace Blah
// Returns an RGB hex string of the color
String to_hex_rgb() const;
// Convers the Color to a uint32_t
uint32_t to_rgba() const;
// Convers the Color to a u32
u32 to_rgba() const;
// Converts the Color to a Vec4
Vec4 to_vec4() const;
// Returns a RGBA Color representation of the integer value
static Color from_rgba(uint32_t value);
static Color from_rgba(u32 value);
// Returns a RGB Color representation of the integer value, with Alpha = 255
static Color from_rgb(uint32_t value);
static Color from_rgb(u32 value);
// Lerps between two colors
static Color lerp(Color a, Color b, float amount);

View File

@ -1,6 +1,6 @@
#pragma once
#include <blah/math/calc.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
namespace Blah
{

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
namespace Blah
{
@ -8,9 +8,9 @@ namespace Blah
public:
Stopwatch();
void reset();
uint64_t microseconds();
uint64_t milliseconds();
u64 microseconds();
u64 milliseconds();
private:
uint64_t start_time;
u64 start_time;
};
}

View File

@ -12,9 +12,9 @@ namespace Blah
BufferStream& operator=(BufferStream&& bs) noexcept;
~BufferStream();
virtual int64_t length() const override { return m_length; }
virtual int64_t position() const override { return m_position; }
virtual int64_t seek(int64_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
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 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; }
@ -25,13 +25,13 @@ namespace Blah
const char* data() const { return m_buffer; }
protected:
virtual int64_t read_into(void* ptr, int64_t length) override;
virtual int64_t write_from(const void* ptr, int64_t length) override;
virtual i64 read_into(void* ptr, i64 length) override;
virtual i64 write_from(const void* ptr, i64 length) override;
private:
char* m_buffer;
int64_t m_capacity;
int64_t m_length;
int64_t m_position;
i64 m_capacity;
i64 m_length;
i64 m_position;
};
}

View File

@ -13,17 +13,17 @@ namespace Blah
FileStream& operator=(FileStream&& fs) noexcept;
~FileStream();
virtual int64_t length() const override;
virtual int64_t position() const override;
virtual int64_t seek(int64_t seekTo) override;
virtual i64 length() const override;
virtual i64 position() const override;
virtual i64 seek(i64 seekTo) override;
virtual bool is_open() const override { return m_handle != nullptr; }
virtual bool is_readable() const override { return m_handle != nullptr && (m_mode == FileMode::ReadWrite || m_mode == FileMode::Read); }
virtual bool is_writable() const override { return m_handle != nullptr && (m_mode == FileMode::ReadWrite || m_mode == FileMode::Write); }
virtual void close() override;
protected:
virtual int64_t read_into(void* ptr, int64_t length) override;
virtual int64_t write_from(const void* ptr, int64_t length) override;
virtual i64 read_into(void* ptr, i64 length) override;
virtual i64 write_from(const void* ptr, i64 length) override;
private:
FileMode m_mode;

View File

@ -7,14 +7,14 @@ namespace Blah
{
public:
MemoryStream();
MemoryStream(char* data, int64_t length);
MemoryStream(char* data, i64 length);
MemoryStream(MemoryStream&& ms) noexcept;
MemoryStream& operator=(MemoryStream&& ms) noexcept;
~MemoryStream() { m_data = nullptr; m_length = m_position = 0; }
virtual int64_t length() const override { return m_length; }
virtual int64_t position() const override { return m_position; }
virtual int64_t seek(int64_t seekTo) override { return m_position = (seekTo < 0 ? 0 : (seekTo > m_length ? m_length : seekTo)); }
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 bool is_open() const override { return m_data != nullptr; }
virtual bool is_readable() const override { return true; }
virtual bool is_writable() const override { return true; }
@ -24,12 +24,12 @@ namespace Blah
const char* data() const { return m_data; }
protected:
virtual int64_t read_into(void* ptr, int64_t length) override;
virtual int64_t write_from(const void* ptr, int64_t length) override;
virtual i64 read_into(void* ptr, i64 length) override;
virtual i64 write_from(const void* ptr, i64 length) override;
private:
char* m_data;
int64_t m_length;
int64_t m_position;
i64 m_length;
i64 m_position;
};
}

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/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 int64_t length() const = 0;
virtual i64 length() const = 0;
// returns the position of the stream
virtual int64_t position() const = 0;
virtual i64 position() const = 0;
// seeks the position of the stream
virtual int64_t seek(int64_t seek_to) = 0;
virtual i64 seek(i64 seek_to) = 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 tream to another stream
int64_t pipe(Stream& to, int64_t length);
i64 pipe(Stream& to, i64 length);
// reads the amount of bytes into the given buffer, and returns the amount read
int64_t read(void* buffer, int64_t length) { return read_into(buffer, length); }
i64 read(void* buffer, i64 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
int64_t write(const void* buffer, int64_t length);
i64 write(const void* buffer, i64 length);
// writes the contents of a string to the stream
int64_t write(const String& string);
i64 write(const String& string);
// writes a number
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
int64_t write(const T& value)
i64 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>
int64_t write(const T& value, Endian endian)
i64 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 int64_t read_into(void* buffer, int64_t length) = 0;
virtual i64 read_into(void* buffer, i64 length) = 0;
// writes from the stream from the given buffer, and returns the number of bytes written
virtual int64_t write_from(const void* buffer, int64_t length) = 0;
virtual i64 write_from(const void* buffer, i64 length) = 0;
};
}

View File

@ -72,9 +72,9 @@ void Str::set_length(int len)
m_length = len;
}
uint32_t Str::utf8_at(int index) const
u32 Str::utf8_at(int index) const
{
uint32_t charcode = 0;
u32 charcode = 0;
int t = (unsigned char)(this->operator[](index++));
if (t < 128)
@ -124,7 +124,7 @@ Str& Str::append(char c)
return *this;
}
Str& Str::append(uint32_t c)
Str& Str::append(u32 c)
{
// one octet
if (c < 0x80)
@ -210,21 +210,21 @@ Str& Str::append_fmt(const char* fmt, ...)
return *this;
}
Str& Str::append_utf16(const uint16_t* start, const uint16_t* end, bool swap_endian)
Str& Str::append_utf16(const u16* start, const u16* end, bool swap_endian)
{
// converts utf16 into utf8
// more info: https://en.wikipedia.org/wiki/UTF-16#Description
const uint16_t surrogate_min = 0xd800u;
const uint16_t surrogate_max = 0xdbffu;
const u16 surrogate_min = 0xd800u;
const u16 surrogate_max = 0xdbffu;
while (start != end)
{
uint16_t next = (*start++);
u16 next = (*start++);
if (swap_endian)
next = ((next & 0xff) << 8 | ((next & 0xff00) >> 8));
uint32_t cp = 0xffff & next;
u32 cp = 0xffff & next;
if ((cp >= surrogate_min && cp <= surrogate_max))
{
@ -232,7 +232,7 @@ Str& Str::append_utf16(const uint16_t* start, const uint16_t* end, bool swap_end
if (swap_endian)
next = ((next & 0xff) << 8 | ((next & 0xff00) >> 8));
uint32_t trail = 0xffff & next;
u32 trail = 0xffff & next;
cp = (cp << 10) + trail + 0x10000u - (surrogate_min << 10) - 0xdc00u;
}

View File

@ -1,5 +1,5 @@
#include <blah/core/app.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <blah/core/time.h>
#include <blah/math/point.h>
#include <blah/graphics/framebuffer.h>
@ -35,8 +35,8 @@ namespace
Config app_config;
bool app_is_running = false;
bool app_is_exiting = false;
uint64_t time_last;
uint64_t time_accumulator = 0;
u64 time_last;
u64 time_accumulator = 0;
void app_iterate()
{
@ -46,9 +46,9 @@ namespace
// update at a fixed timerate
// TODO: allow a non-fixed step update?
{
uint64_t time_target = (uint64_t)((1.0 / app_config.target_framerate) * Time::ticks_per_second);
uint64_t time_curr = PlatformBackend::ticks();
uint64_t time_diff = time_curr - time_last;
u64 time_target = (u64)((1.0 / app_config.target_framerate) * Time::ticks_per_second);
u64 time_curr = PlatformBackend::ticks();
u64 time_diff = time_curr - time_last;
time_last = time_curr;
time_accumulator += time_diff;
@ -66,7 +66,7 @@ namespace
// Do not allow us to fall behind too many updates
// (otherwise we'll get spiral of death)
uint64_t time_maximum = app_config.max_updates * time_target;
u64 time_maximum = app_config.max_updates * time_target;
if (time_accumulator > time_maximum)
time_accumulator = time_maximum;
@ -300,7 +300,7 @@ namespace
return App::draw_height();
}
virtual void clear(Color color, float depth, uint8_t stencil, ClearMask mask) override
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
GraphicsBackend::clear_backbuffer(color, depth, stencil, mask);
}

View File

@ -1,11 +1,11 @@
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <blah/core/app.h>
#include <stdarg.h> // for logging methods
#include <stdio.h> // for sprintf
using namespace Blah;
void Log::print(const char* format, ...)
void Log::info(const char* format, ...)
{
char msg[BLAH_MESSAGE];
va_list ap;

View File

@ -10,8 +10,8 @@ namespace
}
}
uint64_t Time::ticks = 0;
uint64_t Time::previous_ticks = 0;
u64 Time::ticks = 0;
u64 Time::previous_ticks = 0;
double Time::seconds = 0;
double Time::previous_seconds = 0;
float Time::delta = 0;

View File

@ -164,12 +164,12 @@ namespace
{ \
m_batch.elements += 2; \
auto _i = m_indices.expand(6); \
*_i++ = (uint32_t)m_vertices.size() + 0; \
*_i++ = (uint32_t)m_vertices.size() + 1; \
*_i++ = (uint32_t)m_vertices.size() + 2; \
*_i++ = (uint32_t)m_vertices.size() + 0; \
*_i++ = (uint32_t)m_vertices.size() + 2; \
*_i++ = (uint32_t)m_vertices.size() + 3; \
*_i++ = (u32)m_vertices.size() + 0; \
*_i++ = (u32)m_vertices.size() + 1; \
*_i++ = (u32)m_vertices.size() + 2; \
*_i++ = (u32)m_vertices.size() + 0; \
*_i++ = (u32)m_vertices.size() + 2; \
*_i++ = (u32)m_vertices.size() + 3; \
Vertex* _v = m_vertices.expand(4); \
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash); _v++; \
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash); _v++; \
@ -181,9 +181,9 @@ namespace
{ \
m_batch.elements += 1; \
auto* _i = m_indices.expand(3); \
*_i++ = (uint32_t)m_vertices.size() + 0; \
*_i++ = (uint32_t)m_vertices.size() + 1; \
*_i++ = (uint32_t)m_vertices.size() + 2; \
*_i++ = (u32)m_vertices.size() + 0; \
*_i++ = (u32)m_vertices.size() + 1; \
*_i++ = (u32)m_vertices.size() + 2; \
Vertex* _v = m_vertices.expand(3); \
MAKE_VERTEX(_v, m_matrix, px0, py0, tx0, ty0, col0, mult, fill, wash); _v++; \
MAKE_VERTEX(_v, m_matrix, px1, py1, tx1, ty1, col1, mult, fill, wash); _v++; \
@ -423,8 +423,8 @@ void Batch::render_single_batch(RenderPass& pass, const DrawBatch& b, const Mat4
pass.blend = b.blend;
pass.has_scissor = b.scissor.w >= 0 && b.scissor.h >= 0;
pass.scissor = b.scissor;
pass.index_start = (int64_t)b.offset * 3;
pass.index_count = (int64_t)b.elements * 3;
pass.index_start = (i64)b.offset * 3;
pass.index_count = (i64)b.elements * 3;
pass.perform();
}
@ -1046,7 +1046,7 @@ void Batch::str(const SpriteFont& font, const String& text, const Vec2& pos, Tex
else
offset.y = (font.ascent + font.descent + font.height() - font.height_of(text)) * 0.5f;
uint32_t last = 0;
u32 last = 0;
for (int i = 0, l = text.length(); i < l; i++)
{
if (text[i] == '\n')
@ -1067,7 +1067,7 @@ void Batch::str(const SpriteFont& font, const String& text, const Vec2& pos, Tex
}
// get the character
uint32_t next = text.utf8_at(i);
u32 next = text.utf8_at(i);
const auto& ch = font[next];
// draw it, if the subtexture exists

View File

@ -1,7 +1,7 @@
#include <blah/drawing/spritefont.h>
#include <blah/images/font.h>
#include <blah/images/packer.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;
@ -13,15 +13,15 @@ SpriteFont::SpriteFont()
line_gap = 0;
}
const uint32_t ascii[]{ 32, 128, 0 };
const uint32_t* SpriteFont::ASCII = ascii;
const u32 ascii[]{ 32, 128, 0 };
const u32* SpriteFont::ASCII = ascii;
SpriteFont::SpriteFont(const char* file, float size)
{
build(file, size, ASCII);
}
SpriteFont::SpriteFont(const char* file, float size, const uint32_t* charset)
SpriteFont::SpriteFont(const char* file, float size, const u32* charset)
{
build(file, size, charset);
}
@ -31,7 +31,7 @@ SpriteFont::SpriteFont(const Font& font, float size)
build(font, size, ASCII);
}
SpriteFont::SpriteFont(const Font& font, float size, const uint32_t* charset)
SpriteFont::SpriteFont(const Font& font, float size, const u32* charset)
{
build(font, size, charset);
}
@ -79,7 +79,7 @@ float SpriteFont::width_of(const String& text) const
float width = 0;
float line_width = 0;
uint32_t last;
u32 last;
for (int i = 0; i < text.length(); i ++)
{
if (text[i] == '\n')
@ -116,7 +116,7 @@ float SpriteFont::width_of_line(const String& text, int start) const
float width = 0;
uint32_t last;
u32 last;
for (int i = start; i < text.length(); i ++)
{
if (text[i] == '\n')
@ -157,7 +157,7 @@ float SpriteFont::height_of(const String& text) const
return height - line_gap;
}
void SpriteFont::build(const char* file, float sz, const uint32_t* charset)
void SpriteFont::build(const char* file, float sz, const u32* charset)
{
dispose();
@ -166,7 +166,7 @@ void SpriteFont::build(const char* file, float sz, const uint32_t* charset)
build(font, sz, charset);
}
void SpriteFont::build(const Font& font, float size, const uint32_t* charset)
void SpriteFont::build(const Font& font, float size, const u32* charset)
{
dispose();
@ -184,7 +184,7 @@ void SpriteFont::build(const Font& font, float size, const uint32_t* charset)
packer.max_size = 8192;
packer.power_of_two = true;
std::unordered_map<uint32_t, int> glyphs;
std::unordered_map<u32, int> glyphs;
Vector<Color> buffer;
auto ranges = charset;
@ -231,7 +231,7 @@ void SpriteFont::build(const Font& font, float size, const uint32_t* charset)
// add character subtextures
for (auto& it : packer.entries)
if (!it.empty)
m_characters[(uint32_t)it.id].subtexture = Subtexture(m_atlas[it.page], it.packed, it.frame);
m_characters[(u32)it.id].subtexture = Subtexture(m_atlas[it.page], it.packed, it.frame);
// add kerning
for (auto a = glyphs.begin(); a != glyphs.end(); a++)
@ -243,9 +243,9 @@ void SpriteFont::build(const Font& font, float size, const uint32_t* charset)
}
}
float SpriteFont::get_kerning(uint32_t codepoint0, uint32_t codepoint1) const
float SpriteFont::get_kerning(u32 codepoint0, u32 codepoint1) const
{
uint64_t index = ((uint64_t)codepoint0 << 32) | codepoint1;
u64 index = ((u64)codepoint0 << 32) | codepoint1;
auto it = m_kerning.find(index);
if (it != m_kerning.end())
@ -253,9 +253,9 @@ float SpriteFont::get_kerning(uint32_t codepoint0, uint32_t codepoint1) const
return 0.0f;
}
void SpriteFont::set_kerning(uint32_t codepoint0, uint32_t codepoint1, float value)
void SpriteFont::set_kerning(u32 codepoint0, u32 codepoint1, float value)
{
uint64_t index = ((uint64_t)codepoint0 << 32) | codepoint1;
u64 index = ((u64)codepoint0 << 32) | codepoint1;
if (value == 0)
{
@ -267,7 +267,7 @@ void SpriteFont::set_kerning(uint32_t codepoint0, uint32_t codepoint1, float val
}
}
const SpriteFont::Character& SpriteFont::get_character(uint32_t codepoint) const
const SpriteFont::Character& SpriteFont::get_character(u32 codepoint) const
{
static const Character empty;
auto it = m_characters.find(codepoint);
@ -276,7 +276,7 @@ const SpriteFont::Character& SpriteFont::get_character(uint32_t codepoint) const
return empty;
}
const SpriteFont::Character& SpriteFont::operator[](uint32_t codepoint) const
const SpriteFont::Character& SpriteFont::operator[](u32 codepoint) const
{
static const Character empty;
auto it = m_characters.find(codepoint);

View File

@ -1,5 +1,5 @@
#include <blah/graphics/material.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <cstring>
using namespace Blah;
@ -277,7 +277,7 @@ TextureSampler Material::get_sampler(int slot, int index) const
return TextureSampler();
}
void Material::set_value(const char* name, const float* value, int64_t length)
void Material::set_value(const char* name, const float* value, i64 length)
{
BLAH_ASSERT(m_shader, "Material Shader is invalid");
BLAH_ASSERT(length >= 0, "Length must be >= 0");
@ -311,7 +311,7 @@ void Material::set_value(const char* name, const float* value, int64_t length)
Log::warn("No Uniform '%s' exists", name);
}
const float* Material::get_value(const char* name, int64_t* length) const
const float* Material::get_value(const char* name, i64* length) const
{
BLAH_ASSERT(m_shader, "Material Shader is invalid");

View File

@ -1,5 +1,5 @@
#include <blah/graphics/renderpass.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include "../internal/graphics_backend.h"
using namespace Blah;
@ -38,7 +38,7 @@ void RenderPass::perform()
}
// Validate Index Count
int64_t index_count = pass.mesh->index_count();
i64 index_count = pass.mesh->index_count();
if (pass.index_start + pass.index_count > index_count)
{
Log::warn(
@ -54,7 +54,7 @@ void RenderPass::perform()
}
// Validate Instance Count
int64_t instance_count = pass.mesh->instance_count();
i64 instance_count = pass.mesh->instance_count();
if (pass.instance_count > instance_count)
{
Log::warn(

View File

@ -1,7 +1,7 @@
#include <blah/graphics/texture.h>
#include <blah/images/image.h>
#include <blah/streams/stream.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include "../internal/graphics_backend.h"
using namespace Blah;

View File

@ -1,7 +1,7 @@
#include <blah/images/aseprite.h>
#include <blah/streams/filestream.h>
#include <blah/core/filesystem.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#define STBI_NO_STDIO
#define STBI_ONLY_ZLIB
@ -10,7 +10,7 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MUL_UN8(a, b, t) \
((t) = (a) * (uint16_t)(b) + 0x80, ((((t) >> 8) + (t) ) >> 8))
((t) = (a) * (u16)(b) + 0x80, ((((t) >> 8) + (t) ) >> 8))
using namespace Blah;
@ -98,10 +98,10 @@ void Aseprite::parse(Stream& stream)
// header
{
// filesize
stream.read<uint32_t>(Endian::Little);
stream.read<u32>(Endian::Little);
// magic number
auto magic = stream.read<uint16_t>(Endian::Little);
auto magic = stream.read<u16>(Endian::Little);
if (magic != 0xA5E0)
{
BLAH_ERROR("File is not a valid Aseprite file");
@ -109,21 +109,21 @@ void Aseprite::parse(Stream& stream)
}
// main info
frame_count = stream.read<uint16_t>(Endian::Little);
width = stream.read<uint16_t>(Endian::Little);
height = stream.read<uint16_t>(Endian::Little);
mode = static_cast<Aseprite::Modes>(stream.read<uint16_t>(Endian::Little) / 8);
frame_count = stream.read<u16>(Endian::Little);
width = stream.read<u16>(Endian::Little);
height = stream.read<u16>(Endian::Little);
mode = static_cast<Aseprite::Modes>(stream.read<u16>(Endian::Little) / 8);
// don't care about other info
stream.read<uint32_t>(Endian::Little); // Flags
stream.read<uint16_t>(Endian::Little); // Speed (deprecated)
stream.read<uint32_t>(Endian::Little); // Should be 0
stream.read<uint32_t>(Endian::Little); // Should be 0
stream.read<uint8_t>(Endian::Little); // Palette entry
stream.read<u32>(Endian::Little); // Flags
stream.read<u16>(Endian::Little); // Speed (deprecated)
stream.read<u32>(Endian::Little); // Should be 0
stream.read<u32>(Endian::Little); // Should be 0
stream.read<u8>(Endian::Little); // Palette entry
stream.seek(stream.position() + 3); // Ignore these bytes
stream.read<uint16_t>(Endian::Little); // Number of colors (0 means 256 for old sprites)
stream.read<int8_t>(Endian::Little); // Pixel width
stream.read<int8_t>(Endian::Little); // Pixel height
stream.read<u16>(Endian::Little); // Number of colors (0 means 256 for old sprites)
stream.read<i8>(Endian::Little); // Pixel width
stream.read<i8>(Endian::Little); // Pixel height
stream.seek(stream.position() + 92); // For Future
}
@ -133,22 +133,22 @@ void Aseprite::parse(Stream& stream)
for (int i = 0; i < frame_count; i++)
{
auto frameStart = stream.position();
auto frameEnd = frameStart + stream.read<uint32_t>(Endian::Little);
auto frameEnd = frameStart + stream.read<u32>(Endian::Little);
unsigned int chunks = 0;
// frame header
{
auto magic = stream.read<uint16_t>(Endian::Little); // magic number
auto magic = stream.read<u16>(Endian::Little); // magic number
if (magic != 0xF1FA)
{
BLAH_ERROR("File is not a valid Aseprite file");
return;
}
auto old_chunk_count = stream.read<uint16_t>(Endian::Little);
frames[i].duration = stream.read<uint16_t>(Endian::Little);
auto old_chunk_count = stream.read<u16>(Endian::Little);
frames[i].duration = stream.read<u16>(Endian::Little);
stream.seek(stream.position() + 2); // for future
auto new_chunk_count = stream.read<uint32_t>(Endian::Little);
auto new_chunk_count = stream.read<u32>(Endian::Little);
if (old_chunk_count == 0xFFFF)
chunks = new_chunk_count;
@ -163,8 +163,8 @@ void Aseprite::parse(Stream& stream)
for (unsigned int j = 0; j < chunks; j++)
{
auto chunkStart = stream.position();
auto chunkEnd = chunkStart + stream.read<uint32_t>(Endian::Little);
auto chunkType = static_cast<Chunks>(stream.read<uint16_t>(Endian::Little));
auto chunkEnd = chunkStart + stream.read<u32>(Endian::Little);
auto chunkType = static_cast<Chunks>(stream.read<u16>(Endian::Little));
switch (chunkType)
{
@ -189,17 +189,17 @@ void Aseprite::parse_layer(Stream& stream, int frame)
layers.emplace_back();
auto& layer = layers.back();
layer.flag = static_cast<LayerFlags>(stream.read<uint16_t>(Endian::Little));
layer.flag = static_cast<LayerFlags>(stream.read<u16>(Endian::Little));
layer.visible = ((int)layer.flag & (int)LayerFlags::Visible) == (int)LayerFlags::Visible;
layer.type = static_cast<LayerTypes>(stream.read<uint16_t>(Endian::Little));
layer.child_level = stream.read<uint16_t>(Endian::Little);
stream.read<uint16_t>(Endian::Little); // width
stream.read<uint16_t>(Endian::Little); // height
layer.blendmode = stream.read<uint16_t>(Endian::Little);
layer.alpha = stream.read<uint8_t>(Endian::Little);
layer.type = static_cast<LayerTypes>(stream.read<u16>(Endian::Little));
layer.child_level = stream.read<u16>(Endian::Little);
stream.read<u16>(Endian::Little); // width
stream.read<u16>(Endian::Little); // height
layer.blendmode = stream.read<u16>(Endian::Little);
layer.alpha = stream.read<u8>(Endian::Little);
stream.seek(stream.position() + 3); // for future
layer.name.set_length(stream.read<uint16_t>(Endian::Little));
layer.name.set_length(stream.read<u16>(Endian::Little));
stream.read(layer.name.cstr(), layer.name.length());
layer.userdata.color = 0xffffff;
@ -213,20 +213,20 @@ void Aseprite::parse_cel(Stream& stream, int frameIndex, size_t maxPosition)
frame.cels.emplace_back();
auto& cel = frame.cels.back();
cel.layer_index = stream.read<uint16_t>(Endian::Little);
cel.x = stream.read<uint16_t>(Endian::Little);
cel.y = stream.read<uint16_t>(Endian::Little);
cel.alpha = stream.read<uint8_t>(Endian::Little);
cel.layer_index = stream.read<u16>(Endian::Little);
cel.x = stream.read<u16>(Endian::Little);
cel.y = stream.read<u16>(Endian::Little);
cel.alpha = stream.read<u8>(Endian::Little);
cel.linked_frame_index = -1;
auto celType = stream.read<uint16_t>(Endian::Little);
auto celType = stream.read<u16>(Endian::Little);
stream.seek(stream.position() + 7);
// RAW or DEFLATE
if (celType == 0 || celType == 2)
{
auto width = stream.read<uint16_t>(Endian::Little);
auto height = stream.read<uint16_t>(Endian::Little);
auto width = stream.read<u16>(Endian::Little);
auto height = stream.read<u16>(Endian::Little);
auto count = width * height * (int)mode;
cel.image = Image(width, height);
@ -282,7 +282,7 @@ void Aseprite::parse_cel(Stream& stream, int frameIndex, size_t maxPosition)
// this cel directly references a previous cel
else if (celType == 1)
{
cel.linked_frame_index = stream.read<uint16_t>(Endian::Little);
cel.linked_frame_index = stream.read<u16>(Endian::Little);
}
// draw to frame if visible
@ -298,21 +298,21 @@ void Aseprite::parse_cel(Stream& stream, int frameIndex, size_t maxPosition)
void Aseprite::parse_palette(Stream& stream, int frame)
{
/* size */ stream.read<uint32_t>(Endian::Little);
auto start = stream.read<uint32_t>(Endian::Little);
auto end = stream.read<uint32_t>(Endian::Little);
/* size */ stream.read<u32>(Endian::Little);
auto start = stream.read<u32>(Endian::Little);
auto end = stream.read<u32>(Endian::Little);
stream.seek(stream.position() + 8);
palette.resize(palette.size() + (end - start + 1));
for (int p = 0, len = static_cast<int>(end - start) + 1; p < len; p++)
{
auto hasName = stream.read<uint16_t>(Endian::Little);
palette[start + p] = stream.read<uint32_t>(Endian::Little);
auto hasName = stream.read<u16>(Endian::Little);
palette[start + p] = stream.read<u32>(Endian::Little);
if (hasName & 0xF000)
{
int len = stream.read<uint16_t>(Endian::Little);
int len = stream.read<u16>(Endian::Little);
stream.seek(stream.position() + len);
}
}
@ -322,38 +322,38 @@ void Aseprite::parse_user_data(Stream& stream, int frame)
{
if (m_last_userdata != nullptr)
{
auto flags = stream.read<uint32_t>(Endian::Little);
auto flags = stream.read<u32>(Endian::Little);
// has text
if (flags & (1 << 0))
{
m_last_userdata->text.set_length(stream.read<uint16_t>(Endian::Little));
m_last_userdata->text.set_length(stream.read<u16>(Endian::Little));
stream.read(m_last_userdata->text.cstr(), m_last_userdata->text.length());
}
// has color
if (flags & (1 << 1))
m_last_userdata->color = stream.read<uint32_t>(Endian::Little);
m_last_userdata->color = stream.read<u32>(Endian::Little);
}
}
void Aseprite::parse_tag(Stream& stream, int frame)
{
auto count = stream.read<uint16_t>(Endian::Little);
auto count = stream.read<u16>(Endian::Little);
stream.seek(stream.position() + 8);
for (int t = 0; t < count; t++)
{
Tag tag;
tag.from = stream.read<uint16_t>(Endian::Little);
tag.to = stream.read<uint16_t>(Endian::Little);
tag.loops = static_cast<LoopDirections>(stream.read<int8_t>(Endian::Little));
tag.from = stream.read<u16>(Endian::Little);
tag.to = stream.read<u16>(Endian::Little);
tag.loops = static_cast<LoopDirections>(stream.read<i8>(Endian::Little));
stream.seek(stream.position() + 8);
tag.color = Color(stream.read<int8_t>(), stream.read<int8_t>(), stream.read<int8_t>(Endian::Little), 255);
tag.color = Color(stream.read<i8>(), stream.read<i8>(), stream.read<i8>(Endian::Little), 255);
stream.seek(stream.position() + 1);
tag.name.set_length(stream.read<uint16_t>(Endian::Little));
tag.name.set_length(stream.read<u16>(Endian::Little));
stream.read(tag.name.cstr(), tag.name.length());
tags.push_back(tag);
@ -362,12 +362,12 @@ void Aseprite::parse_tag(Stream& stream, int frame)
void Aseprite::parse_slice(Stream& stream, int frame)
{
int count = stream.read<uint32_t>(Endian::Little);
int flags = stream.read<uint32_t>(Endian::Little);
stream.read<uint32_t>(Endian::Little); // reserved
int count = stream.read<u32>(Endian::Little);
int flags = stream.read<u32>(Endian::Little);
stream.read<u32>(Endian::Little); // reserved
String name;
name.set_length(stream.read<uint16_t>(Endian::Little));
name.set_length(stream.read<u16>(Endian::Little));
stream.read(name.cstr(), name.length());
for (int s = 0; s < count; s++)
@ -376,19 +376,19 @@ void Aseprite::parse_slice(Stream& stream, int frame)
auto& slice = slices.back();
slice.name = name;
slice.frame = stream.read<uint32_t>(Endian::Little);
slice.origin.x = stream.read<int32_t>(Endian::Little);
slice.origin.y = stream.read<int32_t>(Endian::Little);
slice.width = stream.read<uint32_t>(Endian::Little);
slice.height = stream.read<uint32_t>(Endian::Little);
slice.frame = stream.read<u32>(Endian::Little);
slice.origin.x = stream.read<i32>(Endian::Little);
slice.origin.y = stream.read<i32>(Endian::Little);
slice.width = stream.read<u32>(Endian::Little);
slice.height = stream.read<u32>(Endian::Little);
// 9 slice (ignored atm)
if (flags & (1 << 0))
{
stream.read<int32_t>(Endian::Little);
stream.read<int32_t>(Endian::Little);
stream.read<uint32_t>(Endian::Little);
stream.read<uint32_t>(Endian::Little);
stream.read<i32>(Endian::Little);
stream.read<i32>(Endian::Little);
stream.read<u32>(Endian::Little);
stream.read<u32>(Endian::Little);
}
// pivot point
@ -396,8 +396,8 @@ void Aseprite::parse_slice(Stream& stream, int frame)
if (flags & (1 << 1))
{
slice.has_pivot = true;
slice.pivot.x = stream.read<uint32_t>(Endian::Little);
slice.pivot.y = stream.read<uint32_t>(Endian::Little);
slice.pivot.x = stream.read<u32>(Endian::Little);
slice.pivot.y = stream.read<u32>(Endian::Little);
}
slice.userdata.color = 0xffffff;

View File

@ -1,7 +1,7 @@
#include <blah/images/font.h>
#include <blah/streams/filestream.h>
#include <blah/math/calc.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;
@ -14,7 +14,7 @@ String GetName(stbtt_fontinfo* font, int nameId)
int length = 0;
// get the name
const uint16_t* ptr = (const uint16_t*)stbtt_GetFontNameStr(font, &length,
const u16* ptr = (const u16*)stbtt_GetFontNameStr(font, &length,
STBTT_PLATFORM_ID_MICROSOFT,
STBTT_MS_EID_UNICODE_BMP,
STBTT_MS_LANG_ENGLISH,

View File

@ -1,7 +1,7 @@
#include <blah/images/image.h>
#include <blah/streams/stream.h>
#include <blah/streams/filestream.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;
@ -18,7 +18,7 @@ namespace
{
int Blah_STBI_Read(void* user, char* data, int size)
{
int64_t read = ((Stream*)user)->read(data, size);
i64 read = ((Stream*)user)->read(data, size);
return (int)read;
}
@ -29,8 +29,8 @@ namespace
int Blah_STBI_Eof(void* user)
{
int64_t position = ((Stream*)user)->position();
int64_t length = ((Stream*)user)->length();
i64 position = ((Stream*)user)->position();
i64 length = ((Stream*)user)->length();
if (position >= length)
return 1;
@ -155,7 +155,7 @@ void Image::from_stream(Stream& stream)
callbacks.skip = Blah_STBI_Skip;
int x, y, comps;
uint8_t* data = stbi_load_from_callbacks(&callbacks, &stream, &x, &y, &comps, 4);
u8* data = stbi_load_from_callbacks(&callbacks, &stream, &x, &y, &comps, 4);
if (data == nullptr)
{
@ -186,9 +186,9 @@ void Image::premultiply()
{
for (int n = 0; n < width * height; n ++)
{
pixels[n].r = (uint8_t)(pixels[n].r * pixels[n].a / 255);
pixels[n].g = (uint8_t)(pixels[n].g * pixels[n].a / 255);
pixels[n].b = (uint8_t)(pixels[n].b * pixels[n].a / 255);
pixels[n].r = (u8)(pixels[n].r * pixels[n].a / 255);
pixels[n].g = (u8)(pixels[n].g * pixels[n].a / 255);
pixels[n].b = (u8)(pixels[n].b * pixels[n].a / 255);
}
}
}

View File

@ -1,5 +1,5 @@
#include <blah/images/packer.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <algorithm>
#include <cstring>
@ -41,22 +41,22 @@ Packer::~Packer()
dispose();
}
void Packer::add(uint64_t id, int width, int height, const Color* pixels)
void Packer::add(u64 id, int width, int height, const Color* pixels)
{
add_entry(id, width, height, pixels);
}
void Packer::add(uint64_t id, const Image& image)
void Packer::add(u64 id, const Image& image)
{
add_entry(id, image.width, image.height, image.pixels);
}
void Packer::add(uint64_t id, const String& path)
void Packer::add(u64 id, const String& path)
{
add(id, Image(path.cstr()));
}
void Packer::add_entry(uint64_t id, int w, int h, const Color* pixels)
void Packer::add_entry(u64 id, int w, int h, const Color* pixels)
{
m_dirty = true;

View File

@ -1,7 +1,7 @@
#include <blah/input/input.h>
#include <blah/core/app.h>
#include <blah/core/time.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <blah/math/point.h>
#include "../internal/input_backend.h"
#include <string.h>
@ -138,7 +138,7 @@ void InputBackend::on_text_utf8(const char* text)
strncat(g_next_state.keyboard.text, text, Blah::Input::max_text_input);
}
void InputBackend::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count, uint16_t vendor, uint16_t product, uint16_t version)
void InputBackend::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count, u16 vendor, u16 product, u16 version)
{
if (index < Blah::Input::max_controllers)
{

View File

@ -1,6 +1,6 @@
#include <blah/input/virtual_axis.h>
#include <blah/core/time.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;

View File

@ -1,6 +1,6 @@
#include <blah/input/virtual_button.h>
#include <blah/core/time.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;

View File

@ -1,6 +1,6 @@
#include <blah/input/virtual_stick.h>
#include <blah/core/time.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;

View File

@ -39,7 +39,7 @@ namespace Blah
void render(const RenderPass& pass);
// Clears the backbuffer
void clear_backbuffer(Color color, float depth, uint8_t stencil, ClearMask mask);
void clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask);
// Creates a new Texture.
// if the Texture is invalid, this should return an empty reference.

View File

@ -5,7 +5,7 @@
#include "../internal/graphics_backend.h"
#include "../internal/platform_backend.h"
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
@ -36,7 +36,7 @@ namespace Blah
struct StoredInputLayout
{
uint32_t shader_hash;
u32 shader_hash;
VertexFormat format;
ID3D11InputLayout* layout;
};
@ -145,6 +145,8 @@ namespace Blah
m_size = width * height * 4;
is_depth_stencil = true;
break;
case TextureFormat::Count:
break;
}
if (!is_depth_stencil)
@ -349,7 +351,7 @@ namespace Blah
return m_attachments[0]->height();
}
virtual void clear(Color color, float depth, uint8_t stencil, ClearMask mask) override
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
float col[4] = { color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f };
@ -386,7 +388,7 @@ namespace Blah
Vector<Vector<float>> fragment_uniform_values;
StackVector<ShaderData::HLSL_Attribute, 16> attributes;
Vector<UniformInfo> uniform_list;
uint32_t hash = 0;
u32 hash = 0;
bool valid = false;
D3D11_Shader(const ShaderData* data)
@ -542,10 +544,10 @@ namespace Blah
class D3D11_Mesh : public Mesh
{
private:
int64_t m_vertex_count = 0;
int64_t m_vertex_capacity = 0;
int64_t m_index_count = 0;
int64_t m_index_capacity = 0;
i64 m_vertex_count = 0;
i64 m_vertex_capacity = 0;
i64 m_index_count = 0;
i64 m_index_capacity = 0;
public:
ID3D11Buffer* vertex_buffer = nullptr;
@ -567,7 +569,7 @@ namespace Blah
index_buffer->Release();
}
virtual void index_data(IndexFormat format, const void* indices, int64_t count) override
virtual void index_data(IndexFormat format, const void* indices, i64 count) override
{
m_index_count = count;
@ -579,8 +581,8 @@ namespace Blah
switch (format)
{
case IndexFormat::UInt16: index_stride = sizeof(int16_t); break;
case IndexFormat::UInt32: index_stride = sizeof(int32_t); break;
case IndexFormat::UInt16: index_stride = sizeof(i16); break;
case IndexFormat::UInt32: index_stride = sizeof(i32); break;
}
if (m_index_capacity > 0 && indices)
@ -621,7 +623,7 @@ namespace Blah
}
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) override
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
@ -669,22 +671,22 @@ namespace Blah
}
}
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) override
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
}
virtual int64_t index_count() const override
virtual i64 index_count() const override
{
return m_index_count;
}
virtual int64_t vertex_count() const override
virtual i64 vertex_count() const override
{
return m_vertex_count;
}
virtual int64_t instance_count() const override
virtual i64 instance_count() const override
{
return 0;
}
@ -764,10 +766,10 @@ namespace Blah
dxgi_device->GetAdapter(&dxgi_adapter);
dxgi_adapter->GetDesc(&adapter_desc);
Log::print("D3D11 %ls", adapter_desc.Description);
Log::info("D3D11 %ls", adapter_desc.Description);
}
else
Log::print("D3D11");
Log::info("D3D11");
}
return true;
@ -1056,7 +1058,7 @@ namespace Blah
}
}
void GraphicsBackend::clear_backbuffer(Color color, float depth, uint8_t stencil, ClearMask mask)
void GraphicsBackend::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask)
{
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
@ -1243,6 +1245,7 @@ namespace Blah
int size = 0;
switch (it.type)
{
case UniformType::None: break;
case UniformType::Float: size = 1; break;
case UniformType::Float2: size = 2; break;
case UniformType::Float3: size = 3; break;
@ -1304,6 +1307,7 @@ namespace Blah
{
switch (format.attributes[i].type)
{
case VertexType::None: break;
case VertexType::Float: it->Format = DXGI_FORMAT_R32_FLOAT; break;
case VertexType::Float2: it->Format = DXGI_FORMAT_R32G32_FLOAT; break;
case VertexType::Float3: it->Format = DXGI_FORMAT_R32G32B32_FLOAT; break;
@ -1320,6 +1324,7 @@ namespace Blah
{
switch (format.attributes[i].type)
{
case VertexType::None: break;
case VertexType::Float: it->Format = DXGI_FORMAT_R32_FLOAT; break;
case VertexType::Float2: it->Format = DXGI_FORMAT_R32G32_FLOAT; break;
case VertexType::Float3: it->Format = DXGI_FORMAT_R32G32B32_FLOAT; break;
@ -1428,18 +1433,21 @@ namespace Blah
switch (sampler.filter)
{
case TextureFilter::None: break;
case TextureFilter::Nearest: desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; break;
case TextureFilter::Linear: desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break;
}
switch (sampler.wrap_x)
{
case TextureWrap::None: break;
case TextureWrap::Clamp: desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; break;
case TextureWrap::Repeat: desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; break;
}
switch (sampler.wrap_y)
{
case TextureWrap::None: break;
case TextureWrap::Clamp: desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; break;
case TextureWrap::Repeat: desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; break;
}

View File

@ -2,7 +2,7 @@
#include "../internal/graphics_backend.h"
#include "../internal/platform_backend.h"
#include <blah/core/log.h>
#include <blah/core/common.h>
namespace Blah
{
@ -134,9 +134,9 @@ namespace Blah
class Dummy_Mesh : public Mesh
{
private:
int64_t m_index_count = 0;
int64_t m_vertex_count = 0;
int64_t m_instance_count = 0;
i64 m_index_count = 0;
i64 m_vertex_count = 0;
i64 m_instance_count = 0;
public:
Dummy_Mesh()
@ -144,32 +144,32 @@ namespace Blah
}
virtual void index_data(IndexFormat format, const void* indices, int64_t count) override
virtual void index_data(IndexFormat format, const void* indices, i64 count) override
{
m_index_count = count;
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) override
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
}
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) override
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
m_instance_count = count;
}
virtual int64_t index_count() const override
virtual i64 index_count() const override
{
return m_index_count;
}
virtual int64_t vertex_count() const override
virtual i64 vertex_count() const override
{
return m_vertex_count;
}
virtual int64_t instance_count() const override
virtual i64 instance_count() const override
{
return m_instance_count;
}
@ -177,7 +177,7 @@ namespace Blah
bool GraphicsBackend::init()
{
Log::print("Dummy Renderer");
Log::info("Dummy Renderer");
return true;
}

View File

@ -2,7 +2,7 @@
#include "../internal/graphics_backend.h"
#include "../internal/platform_backend.h"
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
@ -401,7 +401,7 @@ namespace Blah
else if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
Log::warn("GL (%s:%s) %s", typeName, severityName, message);
else
Log::print("GL (%s) %s", typeName, message);
Log::info("GL (%s) %s", typeName, message);
}
// assign attributes
@ -484,7 +484,7 @@ namespace Blah
components = 4;
}
uint32_t location = (uint32_t)(attribute.index);
u32 location = (u32)(attribute.index);
gl.EnableVertexAttribArray(location);
gl.VertexAttribPointer(location, components, type, attribute.normalized, format.stride, (void*)ptr);
gl.VertexAttribDivisor(location, divisor);
@ -749,7 +749,7 @@ namespace Blah
return m_height;
}
virtual void clear(Color color, float depth, uint8_t stencil, ClearMask mask) override
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
int clear = 0;
@ -967,13 +967,13 @@ namespace Blah
GLuint m_index_buffer;
GLuint m_vertex_buffer;
GLuint m_instance_buffer;
int64_t m_index_count;
int64_t m_vertex_count;
int64_t m_instance_count;
uint16_t m_vertex_size;
uint16_t m_instance_size;
uint8_t m_vertex_attribs_enabled;
uint8_t m_instance_attribs_enabled;
i64 m_index_count;
i64 m_vertex_count;
i64 m_instance_count;
u16 m_vertex_size;
u16 m_instance_size;
u8 m_vertex_attribs_enabled;
u8 m_instance_attribs_enabled;
Vector<GLuint> m_vertex_attribs;
Vector<GLuint> m_instance_attribs;
GLenum m_index_format;
@ -1026,7 +1026,7 @@ namespace Blah
return m_index_size;
}
virtual void index_data(IndexFormat format, const void* indices, int64_t count) override
virtual void index_data(IndexFormat format, const void* indices, i64 count) override
{
m_index_count = count;
@ -1053,7 +1053,7 @@ namespace Blah
gl.BindVertexArray(0);
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) override
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
@ -1074,7 +1074,7 @@ namespace Blah
gl.BindVertexArray(0);
}
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) override
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
m_instance_count = count;
@ -1095,17 +1095,17 @@ namespace Blah
gl.BindVertexArray(0);
}
virtual int64_t index_count() const override
virtual i64 index_count() const override
{
return m_index_count;
}
virtual int64_t vertex_count() const override
virtual i64 vertex_count() const override
{
return m_vertex_count;
}
virtual int64_t instance_count() const override
virtual i64 instance_count() const override
{
return m_instance_count;
}
@ -1147,7 +1147,7 @@ namespace Blah
gl.GetIntegerv(0x0D33, &gl.max_texture_size);
// log
Log::print("OpenGL %s, %s",
Log::info("OpenGL %s, %s",
gl.GetString(GL_VERSION),
gl.GetString(GL_RENDERER));
@ -1496,7 +1496,7 @@ namespace Blah
}
}
void GraphicsBackend::clear_backbuffer(Color color, float depth, uint8_t stencil, ClearMask mask)
void GraphicsBackend::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask)
{
int clear = 0;

View File

@ -37,7 +37,7 @@ namespace Blah
// Call this when a Controller is connected. Note that the Name parameter must be kept valid
// until on_controller_disconnect is called with the same index.
void on_controller_connect(int index, const char* name, int isGamepad, int buttonCount, int axisCount, uint16_t vendor, uint16_t product, uint16_t version);
void on_controller_connect(int index, const char* name, int isGamepad, int buttonCount, int axisCount, u16 vendor, u16 product, u16 version);
// Call this when a controller is disconnected
void on_controller_disconnect(int index);

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/core/filesystem.h>
#include <blah/containers/vector.h>
@ -22,7 +22,7 @@ namespace Blah
void shutdown();
// The time, in ticks (microseconds) since the Application was started
uint64_t ticks();
u64 ticks();
// Called every frame
void frame();
@ -91,19 +91,19 @@ namespace Blah
bool file_open(const char* path, FileHandle* handle, FileMode mode);
// Returns the length of the file
int64_t file_length(FileHandle file);
i64 file_length(FileHandle file);
// Returns the Position of the file
int64_t file_position(FileHandle file);
i64 file_position(FileHandle file);
// Seeks the Position of the file and returns the new position from the start of the file
int64_t file_seek(FileHandle file, int64_t seekTo);
i64 file_seek(FileHandle file, i64 seekTo);
// Reads a specific number of elements of a given size from the file into ptr
int64_t file_read(FileHandle file, void* ptr, int64_t size);
i64 file_read(FileHandle file, void* ptr, i64 size);
// Writes a specific number of elements of the given size from ptr to the file
int64_t file_write(FileHandle file, const void* ptr, int64_t size);
i64 file_write(FileHandle file, const void* ptr, i64 size);
// Closes a file
void file_close(FileHandle file);

View File

@ -6,7 +6,7 @@
#include <blah/input/input.h>
#include <blah/core/app.h>
#include <blah/core/filesystem.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <blah/core/time.h>
#include <SDL.h>
@ -41,7 +41,7 @@ namespace
void sdl_log(void* userdata, int category, SDL_LogPriority priority, const char* message)
{
if (priority <= SDL_LOG_PRIORITY_INFO)
Log::print(message);
Log::info(message);
else if (priority <= SDL_LOG_PRIORITY_WARN)
Log::warn(message);
else
@ -65,7 +65,7 @@ bool PlatformBackend::init(const Config* config)
// Get SDL version
SDL_version version;
SDL_GetVersion(&version);
Log::print("SDL v%i.%i.%i", version.major, version.minor, version.patch);
Log::info("SDL v%i.%i.%i", version.major, version.minor, version.patch);
// initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) != 0)
@ -170,11 +170,11 @@ void PlatformBackend::shutdown()
SDL_Quit();
}
uint64_t PlatformBackend::ticks()
u64 PlatformBackend::ticks()
{
auto counter = SDL_GetPerformanceCounter();
auto per_second = (double)SDL_GetPerformanceFrequency();
return (uint64_t)(counter * (Time::ticks_per_second / per_second));
return (u64)(counter * (Time::ticks_per_second / per_second));
}
// Macro defined by X11 conflicts with MouseButton enum
@ -255,9 +255,9 @@ void PlatformBackend::frame()
const char* name = SDL_JoystickName(ptr);
int button_count = SDL_JoystickNumButtons(ptr);
int axis_count = SDL_JoystickNumAxes(ptr);
uint16_t vendor = SDL_JoystickGetVendor(ptr);
uint16_t product = SDL_JoystickGetProduct(ptr);
uint16_t version = SDL_JoystickGetProductVersion(ptr);
u16 vendor = SDL_JoystickGetVendor(ptr);
u16 product = SDL_JoystickGetProduct(ptr);
u16 version = SDL_JoystickGetProductVersion(ptr);
InputBackend::on_controller_connect(index, name, 0, button_count, axis_count, vendor, product, version);
}
@ -303,9 +303,9 @@ void PlatformBackend::frame()
Sint32 index = event.cdevice.which;
SDL_GameController* ptr = gamepads[index] = SDL_GameControllerOpen(index);
const char* name = SDL_GameControllerName(ptr);
uint16_t vendor = SDL_GameControllerGetVendor(ptr);
uint16_t product = SDL_GameControllerGetProduct(ptr);
uint16_t version = SDL_GameControllerGetProductVersion(ptr);
u16 vendor = SDL_GameControllerGetVendor(ptr);
u16 product = SDL_GameControllerGetProduct(ptr);
u16 version = SDL_GameControllerGetProductVersion(ptr);
InputBackend::on_controller_connect(index, name, 1, 15, 6, vendor, product, version);
}
@ -357,7 +357,7 @@ void PlatformBackend::frame()
void PlatformBackend::sleep(int milliseconds)
{
if (milliseconds >= 0)
SDL_Delay((uint32_t)milliseconds);
SDL_Delay((u32)milliseconds);
}
void PlatformBackend::present()
@ -611,27 +611,27 @@ bool PlatformBackend::file_open(const char* path, PlatformBackend::FileHandle* h
return ptr != nullptr;
}
int64_t PlatformBackend::file_length(PlatformBackend::FileHandle stream)
i64 PlatformBackend::file_length(PlatformBackend::FileHandle stream)
{
return SDL_RWsize((SDL_RWops*)stream);
}
int64_t PlatformBackend::file_position(PlatformBackend::FileHandle stream)
i64 PlatformBackend::file_position(PlatformBackend::FileHandle stream)
{
return SDL_RWtell((SDL_RWops*)stream);
}
int64_t PlatformBackend::file_seek(PlatformBackend::FileHandle stream, int64_t seekTo)
i64 PlatformBackend::file_seek(PlatformBackend::FileHandle stream, i64 seekTo)
{
return SDL_RWseek((SDL_RWops*)stream, seekTo, RW_SEEK_SET);
}
int64_t PlatformBackend::file_read(PlatformBackend::FileHandle stream, void* ptr, int64_t length)
i64 PlatformBackend::file_read(PlatformBackend::FileHandle stream, void* ptr, i64 length)
{
return SDL_RWread((SDL_RWops*)stream, ptr, sizeof(char), length);
}
int64_t PlatformBackend::file_write(PlatformBackend::FileHandle stream, const void* ptr, int64_t length)
i64 PlatformBackend::file_write(PlatformBackend::FileHandle stream, const void* ptr, i64 length)
{
return SDL_RWwrite((SDL_RWops*)stream, ptr, sizeof(char), length);
}

View File

@ -43,16 +43,6 @@ Vec2 Calc::approach(const Vec2& t, const Vec2& target, float delta)
return t + (target - t).normal() * delta;
}
float Calc::clamp(float t, float min, float max)
{
return t < min ? min : (t > max ? max : t);
}
int Calc::clamp_int(int t, int min, int max)
{
return t < min ? min : (t > max ? max : t);
}
float Calc::map(float t, float old_min, float old_max, float new_min, float new_max)
{
return new_min + ((t - old_min) / (old_max - old_min)) * (new_max - new_min);

View File

@ -10,21 +10,21 @@ Color::Color()
: r(0), g(0), b(0), a(0) {}
Color::Color(int rgb) :
r((uint8_t)((rgb & 0xFF0000) >> 16)),
g((uint8_t)((rgb & 0x00FF00) >> 8)),
b((uint8_t)(rgb & 0x0000FF)),
r((u8)((rgb & 0xFF0000) >> 16)),
g((u8)((rgb & 0x00FF00) >> 8)),
b((u8)(rgb & 0x0000FF)),
a(255) {}
Color::Color(int rgb, float alpha) :
r((int)(((uint8_t)((rgb & 0xFF0000) >> 16)) * alpha)),
g((int)(((uint8_t)((rgb & 0x00FF00) >> 8)) * alpha)),
b((int)(((uint8_t)(rgb & 0x0000FF)) * alpha)),
r((int)(((u8)((rgb & 0xFF0000) >> 16)) * alpha)),
g((int)(((u8)((rgb & 0x00FF00) >> 8)) * alpha)),
b((int)(((u8)(rgb & 0x0000FF)) * alpha)),
a((int)(255 * alpha)) {}
Color::Color(uint8_t r, uint8_t g, uint8_t b)
Color::Color(u8 r, u8 g, u8 b)
: r(r), g(g), b(b), a(255) {}
Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Color::Color(u8 r, u8 g, u8 b, u8 a)
: r(r), g(g), b(b), a(a) {}
Color::Color(const Vec4& vec4)
@ -60,13 +60,13 @@ void Color::premultiply()
b = b * a / 255;
}
uint32_t Color::to_rgba() const
u32 Color::to_rgba() const
{
return
((uint32_t)r << 24) |
((uint32_t)g << 16) |
((uint32_t)b << 8) |
(uint32_t)a;
((u32)r << 24) |
((u32)g << 16) |
((u32)b << 8) |
(u32)a;
}
Vec4 Color::to_vec4() const
@ -110,24 +110,24 @@ String Color::to_hex_rgb() const
return str;
}
Color Color::from_rgba(uint32_t value)
Color Color::from_rgba(u32 value)
{
return
{
(uint8_t)((value & 0xFF000000) >> 24),
(uint8_t)((value & 0x00FF0000) >> 16),
(uint8_t)((value & 0x0000FF00) >> 8),
(uint8_t)((value & 0x000000FF))
(u8)((value & 0xFF000000) >> 24),
(u8)((value & 0x00FF0000) >> 16),
(u8)((value & 0x0000FF00) >> 8),
(u8)((value & 0x000000FF))
};
}
Color Color::from_rgb(uint32_t value)
Color Color::from_rgb(u32 value)
{
return
{
(uint8_t)((value & 0xFF0000) >> 16),
(uint8_t)((value & 0x00FF00) >> 8),
(uint8_t)((value & 0x0000FF))
(u8)((value & 0xFF0000) >> 16),
(u8)((value & 0x00FF00) >> 8),
(u8)((value & 0x0000FF))
};
}
@ -137,10 +137,10 @@ Color Color::lerp(Color a, Color b, float amount)
if (amount > 1) amount = 1;
return Color(
(uint8_t)(a.r + (b.r - a.r) * amount),
(uint8_t)(a.g + (b.g - a.g) * amount),
(uint8_t)(a.b + (b.b - a.b) * amount),
(uint8_t)(a.a + (b.a - a.a) * amount)
(u8)(a.r + (b.r - a.r) * amount),
(u8)(a.g + (b.g - a.g) * amount),
(u8)(a.b + (b.b - a.b) * amount),
(u8)(a.a + (b.a - a.a) * amount)
);
}
@ -155,9 +155,9 @@ Color Color::operator*(float multiply) const
Color& Color::operator=(const int rgb)
{
r = (uint8_t)((rgb & 0xFF0000) >> 16);
g = (uint8_t)((rgb & 0x00FF00) >> 8);
b = (uint8_t)(rgb & 0x0000FF);
r = (u8)((rgb & 0xFF0000) >> 16);
g = (u8)((rgb & 0x00FF00) >> 8);
b = (u8)(rgb & 0x0000FF);
a = 255;
return *this;
}

View File

@ -31,7 +31,7 @@ Vec2 Line::closest_point(const Vec2& pt) const
Vec2 v = b - a;
Vec2 w = pt - a;
float t = Vec2::dot(w, v) / Vec2::dot(v, v);
t = Calc::clamp(t, 0, 1);
t = Calc::clamp(t, 0.0f, 1.0f);
return v * t + a;
}

View File

@ -1,5 +1,5 @@
#include <blah/math/mat4x4.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
using namespace Blah;

View File

@ -14,13 +14,13 @@ void Stopwatch::reset()
start_time = std::chrono::duration_cast<std::chrono::microseconds>(system_clock::now().time_since_epoch()).count();
}
uint64_t Stopwatch::milliseconds()
u64 Stopwatch::milliseconds()
{
return microseconds() / 1000;
}
uint64_t Stopwatch::microseconds()
u64 Stopwatch::microseconds()
{
return std::chrono::duration_cast<std::chrono::microseconds>(system_clock::now().time_since_epoch()).count() - start_time;
}

View File

@ -42,7 +42,7 @@ BufferStream::~BufferStream()
delete[] m_buffer;
}
int64_t BufferStream::read_into(void* ptr, int64_t len)
i64 BufferStream::read_into(void* ptr, i64 len)
{
if (m_buffer == nullptr || ptr == nullptr)
return 0;
@ -58,7 +58,7 @@ int64_t BufferStream::read_into(void* ptr, int64_t len)
return len;
}
int64_t BufferStream::write_from(const void* ptr, int64_t len)
i64 BufferStream::write_from(const void* ptr, i64 len)
{
if (len < 0)
return 0;

View File

@ -1,5 +1,5 @@
#include <blah/streams/filestream.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include "../internal/platform_backend.h"
#include <string.h>
@ -39,7 +39,7 @@ FileStream::~FileStream()
PlatformBackend::file_close(m_handle);
}
int64_t FileStream::length() const
i64 FileStream::length() const
{
if (m_handle == nullptr)
return 0;
@ -47,7 +47,7 @@ int64_t FileStream::length() const
return PlatformBackend::file_length(m_handle);
}
int64_t FileStream::position() const
i64 FileStream::position() const
{
if (m_handle == nullptr)
return 0;
@ -55,7 +55,7 @@ int64_t FileStream::position() const
return PlatformBackend::file_position(m_handle);
}
int64_t FileStream::seek(int64_t seek_to)
i64 FileStream::seek(i64 seek_to)
{
if (m_handle == nullptr)
return 0;
@ -63,7 +63,7 @@ int64_t FileStream::seek(int64_t seek_to)
return PlatformBackend::file_seek(m_handle, seek_to);
}
int64_t FileStream::read_into(void* ptr, int64_t length)
i64 FileStream::read_into(void* ptr, i64 length)
{
if (m_handle == nullptr)
{
@ -74,7 +74,7 @@ int64_t FileStream::read_into(void* ptr, int64_t length)
return PlatformBackend::file_read(m_handle, ptr, length);
}
int64_t FileStream::write_from(const void* ptr, int64_t length)
i64 FileStream::write_from(const void* ptr, i64 length)
{
if (length <= 0)
return 0;

View File

@ -6,7 +6,7 @@ using namespace Blah;
MemoryStream::MemoryStream()
: m_data(nullptr), m_length(0), m_position(0) {}
MemoryStream::MemoryStream(char* data, int64_t length)
MemoryStream::MemoryStream(char* data, i64 length)
: m_data(data), m_length(length), m_position(0) {}
MemoryStream::MemoryStream(MemoryStream&& src) noexcept
@ -28,7 +28,7 @@ MemoryStream& MemoryStream::operator=(MemoryStream&& src) noexcept
return *this;
}
int64_t MemoryStream::read_into(void* ptr, int64_t len)
i64 MemoryStream::read_into(void* ptr, i64 len)
{
if (len < 0 || ptr == nullptr)
return 0;
@ -41,7 +41,7 @@ int64_t MemoryStream::read_into(void* ptr, int64_t len)
return len;
}
int64_t MemoryStream::write_from(const void* ptr, int64_t len)
i64 MemoryStream::write_from(const void* ptr, i64 len)
{
if (len < 0 || ptr == nullptr)
return 0;

View File

@ -4,10 +4,10 @@
using namespace Blah;
int64_t Stream::pipe(Stream& stream, int64_t length)
i64 Stream::pipe(Stream& stream, i64 length)
{
const int BUFFER_LENGTH = 4096;
int64_t result = 0;
i64 result = 0;
char buffer[BUFFER_LENGTH];
while (length > 0)
@ -59,12 +59,12 @@ String Stream::read_line()
return result;
}
int64_t Stream::write(const void* buffer, int64_t length)
i64 Stream::write(const void* buffer, i64 length)
{
return write_from(buffer, length);
}
int64_t Stream::write(const String& string)
i64 Stream::write(const String& string)
{
return write_from(string.begin(), string.length());
}