Skip to content

Commit

Permalink
Change format style
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Dec 31, 2019
1 parent 05698d8 commit 2ed7bab
Show file tree
Hide file tree
Showing 134 changed files with 3,045 additions and 3,025 deletions.
14 changes: 14 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4

BreakBeforeBraces: Stroustrup
FixNamespaceComments: true
IndentCaseLabels: true
NamespaceIndentation: None

BreakConstructorInitializersBeforeComma: true

AllowShortFunctionsOnASingleLine: None

ColumnLimit: 80
32 changes: 12 additions & 20 deletions Source/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
#include "Application.h"
#include <iostream>
#include "States/PlayingState.h"
#include "World/Block/BlockDatabase.h"
#include <iostream>

Application::Application(const Config& config)
: m_context (config)
, m_camera (config)
, m_config (config)
Application::Application(const Config &config)
: m_context(config)
, m_camera(config)
, m_config(config)
{
BlockDatabase::get();
pushState<StatePlaying>(*this, config);
}

float g_timeElapsed = 0;


void Application::runLoop()
{
sf::Clock dtTimer;
sf::Clock dt;

sf::Time m;

while (m_context.window.isOpen() && !m_states.empty())
{
while (m_context.window.isOpen() && !m_states.empty()) {
auto deltaTime = dtTimer.restart();
auto& state = *m_states.back();
auto &state = *m_states.back();

state.handleInput();
state.update(deltaTime.asSeconds());
Expand All @@ -35,8 +33,7 @@ void Application::runLoop()
m_masterRenderer.finishRender(m_context.window, m_camera);

handleEvents();
if (m_isPopState)
{
if (m_isPopState) {
m_isPopState = false;
m_states.pop_back();
}
Expand All @@ -50,18 +47,15 @@ void Application::runLoop()
void Application::handleEvents()
{
sf::Event e;
while (m_context.window.pollEvent(e))
{
m_states.back()->handleEvent(e);
switch(e.type)
{
while (m_context.window.pollEvent(e)) {
m_states.back()->handleEvent(e);
switch (e.type) {
case sf::Event::Closed:
m_context.window.close();
break;

case sf::Event::KeyPressed:
switch(e.key.code)
{
switch (e.key.code) {
case sf::Keyboard::Escape:
m_context.window.close();
break;
Expand All @@ -77,7 +71,6 @@ void Application::handleEvents()
}
}


void Application::popState()
{
m_isPopState = true;
Expand All @@ -92,4 +85,3 @@ void Application::turnOnMouse()
{
m_context.window.setMouseCursorVisible(true);
}

62 changes: 33 additions & 29 deletions Source/Application.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
#ifndef APPLICATION_H_INCLUDED
#define APPLICATION_H_INCLUDED

#include <vector>
#include <memory>
#include <vector>

#include "States/StateBase.h"
#include "Renderer/RenderMaster.h"
#include "States/StateBase.h"

#include "Context.h"
#include "Camera.h"
#include "Context.h"

float extern g_timeElapsed;

class Application
{

public:
Application(const Config& config);
class Application {

public:
Application(const Config &config);

void runLoop();
void runLoop();

template<typename T, typename... Args>
void pushState(Args&&... args)
{
m_states.push_back(std::make_unique<T>(std::forward<Args>(args)...));
auto& s = m_states.back();
s->onOpen();
}
template <typename T, typename... Args> void pushState(Args &&... args)
{
m_states.push_back(std::make_unique<T>(std::forward<Args>(args)...));
auto &s = m_states.back();
s->onOpen();
}

void popState();
void popState();

Camera& getCamera() { return m_camera; }
Camera &getCamera()
{
return m_camera;
}

const sf::Window& getWindow() const { return m_context.window; }
const sf::Window &getWindow() const
{
return m_context.window;
}

void turnOffMouse();
void turnOnMouse ();
void turnOffMouse();
void turnOnMouse();

private:
void handleEvents();
private:
void handleEvents();

std::vector<std::unique_ptr<StateBase>> m_states;
std::vector<std::unique_ptr<StateBase>> m_states;

Context m_context;
RenderMaster m_masterRenderer;
Camera m_camera;
Context m_context;
RenderMaster m_masterRenderer;
Camera m_camera;

const Config& m_config;
const Config &m_config;

bool m_isPopState = false;
bool m_isPopState = false;
};

#endif // APPLICATION_H_INCLUDED
20 changes: 10 additions & 10 deletions Source/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "Maths/Matrix.h"

Camera::Camera(const Config& config) noexcept
: m_config (config)
Camera::Camera(const Config &config) noexcept
: m_config(config)
{
m_projectionMatrix = makeProjectionMatrix(config);

Expand All @@ -12,36 +12,36 @@ Camera::Camera(const Config& config) noexcept

void Camera::update() noexcept
{
position = {m_pEntity->position.x, m_pEntity->position.y + 0.6f, m_pEntity->position.z};
position = {m_pEntity->position.x, m_pEntity->position.y + 0.6f,
m_pEntity->position.z};
rotation = m_pEntity->rotation;

m_viewMatrix = makeViewMatrix(*this);
m_viewMatrix = makeViewMatrix(*this);
m_projViewMatrx = m_projectionMatrix * m_viewMatrix;
m_frustum.update(m_projViewMatrx);
}

void Camera::hookEntity(const Entity& entity) noexcept
void Camera::hookEntity(const Entity &entity) noexcept
{
m_pEntity = &entity;
}

const glm::mat4& Camera::getViewMatrix() const noexcept
const glm::mat4 &Camera::getViewMatrix() const noexcept
{
return m_viewMatrix;
}

const glm::mat4& Camera::getProjMatrix() const noexcept
const glm::mat4 &Camera::getProjMatrix() const noexcept
{
return m_projectionMatrix;
}

const glm::mat4& Camera::getProjectionViewMatrix() const noexcept
const glm::mat4 &Camera::getProjectionViewMatrix() const noexcept
{
return m_projViewMatrx;
}

const ViewFrustum& Camera::getFrustum() const noexcept
const ViewFrustum &Camera::getFrustum() const noexcept
{
return m_frustum;
}

41 changes: 19 additions & 22 deletions Source/Camera.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
#ifndef CAMERA_H_INCLUDED
#define CAMERA_H_INCLUDED

#include "Maths/glm.h"
#include "Maths/Frustum.h"
#include "Entity.h"
#include "Config.h"
#include "Entity.h"
#include "Maths/Frustum.h"
#include "Maths/glm.h"

class Camera : public Entity
{
public:
Camera(const Config& config) noexcept;

void update() noexcept;
void hookEntity(const Entity& entity) noexcept;

const glm::mat4& getViewMatrix () const noexcept;
const glm::mat4& getProjMatrix () const noexcept;
const glm::mat4& getProjectionViewMatrix () const noexcept;
class Camera : public Entity {
public:
Camera(const Config &config) noexcept;

const ViewFrustum& getFrustum() const noexcept;
void update() noexcept;
void hookEntity(const Entity &entity) noexcept;

private:
const Entity* m_pEntity;
const glm::mat4 &getViewMatrix() const noexcept;
const glm::mat4 &getProjMatrix() const noexcept;
const glm::mat4 &getProjectionViewMatrix() const noexcept;

ViewFrustum m_frustum;
const ViewFrustum &getFrustum() const noexcept;

glm::mat4 m_projectionMatrix;
glm::mat4 m_viewMatrix;
glm::mat4 m_projViewMatrx;
private:
const Entity *m_pEntity;

Config m_config;
ViewFrustum m_frustum;

glm::mat4 m_projectionMatrix;
glm::mat4 m_viewMatrix;
glm::mat4 m_projViewMatrx;

Config m_config;
};

#endif // CAMERA_H_INCLUDED
13 changes: 6 additions & 7 deletions Source/Config.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED

struct Config
{
int windowX = 1280;
int windowY = 720;
bool isFullscreen = false;
int renderDistance = 16;
int fov = 90;
struct Config {
int windowX = 1280;
int windowY = 720;
bool isFullscreen = false;
int renderDistance = 16;
int fov = 90;
};

#endif // CONFIG_H_INCLUDED
19 changes: 9 additions & 10 deletions Source/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@
unsigned int g_X;
unsigned int g_Y;

Context::Context(const Config& config)
Context::Context(const Config &config)
{
sf::ContextSettings settings;
settings.antialiasingLevel = 0;
settings.majorVersion = 3;
settings.minorVersion = 3;
settings.depthBits = 24;
settings.stencilBits = 8;
//settings.attributeFlags = sf::ContextSettings::Core;
//This is no longer necessary due to the Mac Support update.
if(config.isFullscreen)
{
window.create(sf::VideoMode::getDesktopMode(), "MineCraft Week", sf::Style::Fullscreen, settings);
// settings.attributeFlags = sf::ContextSettings::Core;
// This is no longer necessary due to the Mac Support update.

if (config.isFullscreen) {
window.create(sf::VideoMode::getDesktopMode(), "MineCraft Week",
sf::Style::Fullscreen, settings);
}
else
{
else {
sf::VideoMode winMode(config.windowX, config.windowY);
window.create(winMode, "MineCraft Week", sf::Style::Close, settings);
}

if (!gladLoadGL()) {

exit(-1);
}

Expand Down
5 changes: 2 additions & 3 deletions Source/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#include "Config.h"

struct Context
{
Context(const Config& config);
struct Context {
Context(const Config &config);

sf::Window window;
};
2 changes: 1 addition & 1 deletion Source/Controller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Controller.h"

//WIP
// WIP
/*
glm::vec3 Controller::translateInput()
{
Expand Down
9 changes: 4 additions & 5 deletions Source/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#include "Maths/glm.h"
#include <SFML/Graphics.hpp>

//WIP
class Controller
{
glm::vec3 translateInput();
sf::Vector2i mouseInput();
// WIP
class Controller {
glm::vec3 translateInput();
sf::Vector2i mouseInput();
};

#endif // CONTROLLER_H_INCLUDED
Loading

0 comments on commit 2ed7bab

Please sign in to comment.