Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed May 15, 2017
1 parent 7deee9e commit e531828
Show file tree
Hide file tree
Showing 24 changed files with 322 additions and 315 deletions.
60 changes: 32 additions & 28 deletions MAGE/MAGE/src/font/sprite_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,29 @@ namespace mage {
const SpriteTransform &transform, const XMVECTOR &color, SpriteEffect effects) const {
Assert(str);

static_assert(SpriteEffect_FlipHorizontally == 1 && SpriteEffect_FlipVertically == 2,
static_assert(
static_cast< unsigned int >(SpriteEffect::FlipHorizontally) == 1 &&
static_cast< unsigned int >(SpriteEffect::FlipVertically) == 2,
"The following tables must be updated to match");
// Lookup table indicates which way to move along each axes for each SpriteEffect.
static const XMVECTORF32 axis_direction_table[4] = {
{-1.0f, -1.0f}, //SpriteEffect_None
{ 1.0f, -1.0f}, //SpriteEffect_FlipHorizontally
{-1.0f, 1.0f}, //SpriteEffect_FlipVertically
{ 1.0f, 1.0f} //SpriteEffect_FlipBoth
{-1.0f, -1.0f}, //SpriteEffect::None
{ 1.0f, -1.0f}, //SpriteEffect::FlipHorizontally
{-1.0f, 1.0f}, //SpriteEffect::FlipVertically
{ 1.0f, 1.0f} //SpriteEffect::FlipBoth
};
// Lookup table indiucates which axes are mirrored for each SpriteEffect.
static const XMVECTORF32 axis_is_mirrored_table[4] = {
{ 0.0f, 0.0f }, //SpriteEffect_None
{ 1.0f, 0.0f }, //SpriteEffect_FlipHorizontally
{ 0.0f, 1.0f }, //SpriteEffect_FlipVertically
{ 1.0f, 1.0f } //SpriteEffect_FlipBoth
{ 0.0f, 0.0f }, //SpriteEffect::None
{ 1.0f, 0.0f }, //SpriteEffect::FlipHorizontally
{ 0.0f, 1.0f }, //SpriteEffect::FlipVertically
{ 1.0f, 1.0f } //SpriteEffect::FlipBoth
};

const XMFLOAT2 rotation_origin = transform.GetRotationOrigin();
XMVECTOR base_offset = XMLoadFloat2(&rotation_origin);
if (effects != SpriteEffect_None) {
base_offset -= MeasureString(str) * axis_is_mirrored_table[effects & 3];
if (effects != SpriteEffect::None) {
base_offset -= MeasureString(str) * axis_is_mirrored_table[static_cast< size_t >(effects) & 3];
}

float x = 0;
Expand Down Expand Up @@ -233,14 +235,14 @@ namespace mage {

if (!iswspace(character) || width > 1 || height > 1) {
const XMVECTOR top_left = XMVectorSet(x, y + glyph->m_offset_y, 0.0f, 0.0f);
const XMVECTOR &flip = axis_direction_table[effects & 3];
const XMVECTOR &flip = axis_direction_table[static_cast< size_t >(effects) & 3];
XMVECTOR offset = XMVectorMultiplyAdd(top_left, flip, base_offset);

if (effects != SpriteEffect_None) {
if (effects != SpriteEffect::None) {
const XMVECTOR rect = XMLoadInt4(reinterpret_cast<const uint32_t *>(&(glyph->m_sub_rectangle)));
XMVECTOR glyph_rect = XMConvertVectorIntToFloat(rect, 0);
glyph_rect = XMVectorSwizzle< 2, 3, 0, 1 >(glyph_rect) - glyph_rect;
const XMVECTOR &mirror = axis_is_mirrored_table[effects & 3];
const XMVECTOR &mirror = axis_is_mirrored_table[static_cast< size_t >(effects) & 3];
offset = XMVectorMultiplyAdd(glyph_rect, mirror, offset);
}

Expand All @@ -258,27 +260,29 @@ namespace mage {
void SpriteFont::DrawString(SpriteBatch &sprite_batch, const vector< ColorString > &text,
const SpriteTransform &transform, SpriteEffect effects) const {

static_assert(SpriteEffect_FlipHorizontally == 1 && SpriteEffect_FlipVertically == 2,
static_assert(
static_cast< unsigned int >(SpriteEffect::FlipHorizontally) == 1 &&
static_cast< unsigned int >(SpriteEffect::FlipVertically) == 2,
"The following tables must be updated to match");
// Lookup table indicates which way to move along each axes for each SpriteEffect.
static const XMVECTORF32 axis_direction_table[4] = {
{ -1.0f, -1.0f }, //SpriteEffect_None
{ 1.0f, -1.0f }, //SpriteEffect_FlipHorizontally
{ -1.0f, 1.0f }, //SpriteEffect_FlipVertically
{ 1.0f, 1.0f } //SpriteEffect_FlipBoth
{ -1.0f, -1.0f }, //SpriteEffect::None
{ 1.0f, -1.0f }, //SpriteEffect::FlipHorizontally
{ -1.0f, 1.0f }, //SpriteEffect::FlipVertically
{ 1.0f, 1.0f } //SpriteEffect::FlipBoth
};
// Lookup table indiucates which axes are mirrored for each SpriteEffect.
static const XMVECTORF32 axis_is_mirrored_table[4] = {
{ 0.0f, 0.0f }, //SpriteEffect_None
{ 1.0f, 0.0f }, //SpriteEffect_FlipHorizontally
{ 0.0f, 1.0f }, //SpriteEffect_FlipVertically
{ 1.0f, 1.0f } //SpriteEffect_FlipBoth
{ 0.0f, 0.0f }, //SpriteEffect::None
{ 1.0f, 0.0f }, //SpriteEffect::FlipHorizontally
{ 0.0f, 1.0f }, //SpriteEffect::FlipVertically
{ 1.0f, 1.0f } //SpriteEffect::FlipBoth
};

const XMFLOAT2 rotation_origin = transform.GetRotationOrigin();
XMVECTOR base_offset = XMLoadFloat2(&rotation_origin);
if (effects != SpriteEffect_None) {
base_offset -= MeasureString(text) * axis_is_mirrored_table[effects & 3];
if (effects != SpriteEffect::None) {
base_offset -= MeasureString(text) * axis_is_mirrored_table[static_cast< size_t >(effects) & 3];
}

float x = 0;
Expand Down Expand Up @@ -314,14 +318,14 @@ namespace mage {

if (!iswspace(character) || width > 1 || height > 1) {
const XMVECTOR top_left = XMVectorSet(x, y + glyph->m_offset_y, 0.0f, 0.0f);
const XMVECTOR &flip = axis_direction_table[effects & 3];
const XMVECTOR &flip = axis_direction_table[static_cast< size_t >(effects) & 3];
XMVECTOR offset = XMVectorMultiplyAdd(top_left, flip, base_offset);

if (effects != SpriteEffect_None) {
if (effects != SpriteEffect::None) {
const XMVECTOR rect = XMLoadInt4(reinterpret_cast<const uint32_t *>(&(glyph->m_sub_rectangle)));
XMVECTOR glyph_rect = XMConvertVectorIntToFloat(rect, 0);
glyph_rect = XMVectorSwizzle< 2, 3, 0, 1 >(glyph_rect) - glyph_rect;
const XMVECTOR &mirror = axis_is_mirrored_table[effects & 3];
const XMVECTOR &mirror = axis_is_mirrored_table[static_cast< size_t >(effects) & 3];
offset = XMVectorMultiplyAdd(glyph_rect, mirror, offset);
}

Expand Down
4 changes: 2 additions & 2 deletions MAGE/MAGE/src/font/sprite_font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace mage {
const wchar_t *str,
const SpriteTransform &transform,
const XMVECTOR &color = Colors::White,
SpriteEffect effects = SpriteEffect_None) const;
SpriteEffect effects = SpriteEffect::None) const;

/**
Draws the given text with this sprite font using the given sprite batch.
Expand All @@ -132,7 +132,7 @@ namespace mage {
void DrawString(SpriteBatch &sprite_batch,
const vector< ColorString > &text,
const SpriteTransform &transform,
SpriteEffect effects = SpriteEffect_None) const;
SpriteEffect effects = SpriteEffect::None) const;

/**
Returns the size of the given string with this sprite font in pixels.
Expand Down
14 changes: 7 additions & 7 deletions MAGE/MAGE/src/mesh/obj/obj_reader.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,34 +238,34 @@ namespace mage {
if (str_contains(token, "//")) {
// v1//vn1
const char *index_end = strchr(token, '/');
if (StringToUInt32(token, index_end, vertex_index) == TokenResult_Invalid) {
if (StringToUInt32(token, index_end, vertex_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid vertex index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}
if (StringToUInt32(index_end + 2, normal_index) == TokenResult_Invalid) {
if (StringToUInt32(index_end + 2, normal_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid normal index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}
}
else if (str_contains(token, '/')) {
// v1/vt1 or v1/vt1/vn1
const char *index_end = strchr(token, '/');
if (StringToUInt32(token, index_end, vertex_index) == TokenResult_Invalid) {
if (StringToUInt32(token, index_end, vertex_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid vertex index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}

if (str_contains(index_end + 1, '/')) {
const char *texture_end = strchr(index_end + 1, '/');
if (StringToUInt32(index_end + 1, texture_end, texture_index) == TokenResult_Invalid) {
if (StringToUInt32(index_end + 1, texture_end, texture_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid texture index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}
if (StringToUInt32(texture_end + 1, normal_index) == TokenResult_Invalid) {
if (StringToUInt32(texture_end + 1, normal_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid normal index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}
}
else if (StringToUInt32(index_end + 1, texture_index) == TokenResult_Invalid) {
else if (StringToUInt32(index_end + 1, texture_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid texture index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}
}
else if (StringToUInt32(token, vertex_index) == TokenResult_Invalid) {
else if (StringToUInt32(token, vertex_index) == TokenResult::Invalid) {
throw FormattedException("%ls: line %u: invalid vertex index value found in %s.", GetFilename().c_str(), GetCurrentLineNumber(), token);
}

Expand Down
10 changes: 5 additions & 5 deletions MAGE/MAGE/src/rendering/device_enumeration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ namespace mage {
Edit_SetText(GetDlgItem(hwndDlg, IDC_DISPLAY_ADAPTER), desc.Description);

if (m_settings_script->IsEmpty()) {
m_settings_script->AddVariable(VariableType_Bool, "windowed", true);
m_settings_script->AddVariable(VariableType_Bool, "vsync", false);
m_settings_script->AddVariable(VariableType_Int, "bpp", 0);
m_settings_script->AddVariable(VariableType_Int, "resolution", 0);
m_settings_script->AddVariable(VariableType_Int, "refresh", 0);
m_settings_script->AddVariable(VariableType::Bool, "windowed", true);
m_settings_script->AddVariable(VariableType::Bool, "vsync", false);
m_settings_script->AddVariable(VariableType::Int, "bpp", 0);
m_settings_script->AddVariable(VariableType::Int, "resolution", 0);
m_settings_script->AddVariable(VariableType::Int, "refresh", 0);
}

// Load the windowed state.
Expand Down
2 changes: 1 addition & 1 deletion MAGE/MAGE/src/scene/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace mage {
SharedPtr< OmniLightNode > CreateOmniLightNode();
SharedPtr< SpotLightNode > CreateSpotLightNode();
SharedPtr< ModelNode > CreateModelNode(const ModelDescriptor &desc,
BRDFType brdf = BRDFType_Unknown);
BRDFType brdf = BRDFType::Unknown);
SharedPtr< ModelNode > CreateModelNode(const ModelDescriptor &desc,
const CombinedShader &shader);

Expand Down
42 changes: 21 additions & 21 deletions MAGE/MAGE/src/scripting/variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ namespace mage {
An enumeration of the different (scripting) variable types.
This contains:
@c VariableType_Bool,
@c VariableType_Int,
@c VariableType_Int2,
@c VariableType_Int3,
@c VariableType_Float,
@c VariableType_Float2,
@c VariableType_Float3,
@c VariableType_Float4,
@c VariableType_Color and
@c VariableType_String.
@c Bool,
@c Int,
@c Int2,
@c Int3,
@c Float,
@c Float2,
@c Float3,
@c Float4,
@c Color and
@c VariableType::String.
*/
enum VariableType {
VariableType_Bool,
VariableType_Int,
VariableType_Int2,
VariableType_Int3,
VariableType_Float,
VariableType_Float2,
VariableType_Float3,
VariableType_Float4,
VariableType_Color,
VariableType_String
enum struct VariableType {
Bool,
Int,
Int2,
Int3,
Float,
Float2,
Float3,
Float4,
Color,
String
};

/**
Expand Down
20 changes: 10 additions & 10 deletions MAGE/MAGE/src/scripting/vs/vs_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ namespace mage {
void VSReader::ReadVSBool() {
const string name = ReadString();
const bool value = ReadBool();
m_variable_buffer.push_back(Variable(VariableType_Bool, name, value));
m_variable_buffer.push_back(Variable(VariableType::Bool, name, value));
}

void VSReader::ReadVSInt() {
const string name = ReadString();
const int value = ReadInt32();
m_variable_buffer.push_back(Variable(VariableType_Int, name, value));
m_variable_buffer.push_back(Variable(VariableType::Int, name, value));
}

void VSReader::ReadVSInt2() {
const string name = ReadString();
const int x = ReadInt32();
const int y = ReadInt32();
const int2 value(x, y);
m_variable_buffer.push_back(Variable(VariableType_Int2, name, value));
m_variable_buffer.push_back(Variable(VariableType::Int2, name, value));
}

void VSReader::ReadVSInt3() {
Expand All @@ -93,21 +93,21 @@ namespace mage {
const int y = ReadInt32();
const int z = ReadInt32();
const int3 value(x, y, z);
m_variable_buffer.push_back(Variable(VariableType_Int3, name, value));
m_variable_buffer.push_back(Variable(VariableType::Int3, name, value));
}

void VSReader::ReadVSFloat() {
const string name = ReadString();
const float value = ReadFloat();
m_variable_buffer.push_back(Variable(VariableType_Float, name, value));
m_variable_buffer.push_back(Variable(VariableType::Float, name, value));
}

void VSReader::ReadVSFloat2() {
const string name = ReadString();
const float x = ReadFloat();
const float y = ReadFloat();
const float2 value(x, y);
m_variable_buffer.push_back(Variable(VariableType_Float2, name, value));
m_variable_buffer.push_back(Variable(VariableType::Float2, name, value));
}

void VSReader::ReadVSFloat3() {
Expand All @@ -116,7 +116,7 @@ namespace mage {
const float y = ReadFloat();
const float z = ReadFloat();
const float3 value(x, y, z);
m_variable_buffer.push_back(Variable(VariableType_Float3, name, value));
m_variable_buffer.push_back(Variable(VariableType::Float3, name, value));
}

void VSReader::ReadVSFloat4() {
Expand All @@ -126,7 +126,7 @@ namespace mage {
const float z = ReadFloat();
const float w = ReadFloat();
const float4 value(x, y, z, w);
m_variable_buffer.push_back(Variable(VariableType_Float4, name, value));
m_variable_buffer.push_back(Variable(VariableType::Float4, name, value));
}

void VSReader::ReadVSColor() {
Expand All @@ -136,12 +136,12 @@ namespace mage {
const float z = ReadFloat();
const float w = ReadFloat();
const color value(x, y, z, w);
m_variable_buffer.push_back(Variable(VariableType_Color, name, value));
m_variable_buffer.push_back(Variable(VariableType::Color, name, value));
}

void VSReader::ReadVSString() {
const string name = ReadString();
const string value = ReadQuotedString();
m_variable_buffer.push_back(Variable(VariableType_String, name, value));
m_variable_buffer.push_back(Variable(VariableType::String, name, value));
}
}
Loading

0 comments on commit e531828

Please sign in to comment.