Skip to content

Commit

Permalink
Merge branch 'code-cleanup'
Browse files Browse the repository at this point in the history
pulls #1
  • Loading branch information
Tumble committed Feb 16, 2021
2 parents 771655e + e8c1298 commit 20becf2
Show file tree
Hide file tree
Showing 27 changed files with 533 additions and 503 deletions.
30 changes: 30 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BasedOnStyle: LLVM

IndentWidth: 3
TabWidth: 3
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 3
ContinuationIndentWidth: 3
ObjCBlockIndentWidth: 3
UseTab: ForContinuationAndIndentation
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
NamespaceIndentation: All

DerivePointerAlignment: false
PointerAlignment: Left

BreakBeforeBraces: Attach
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: None

AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
#AllowShortEnumsOnASingleLine: true # this breaks things?
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false

AlignAfterOpenBracket: DontAlign
FixNamespaceComments: false
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/dep/")

add_subdirectory(dep)
add_subdirectory(engine)
add_subdirectory(engine)
22 changes: 10 additions & 12 deletions dep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ message(NOTICE "OPENGL_LIBRARY " ${OPENGL_LIBRARY})
message(NOTICE "OPENGL_LIBRARIES " ${OPENGL_LIBRARIES})
message(NOTICE "OPENGL_INCLUDE_DIR " ${OPENGL_INCLUDE_DIR})


# glew
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
message(NOTICE "GLEW_LIBRARIES " ${GLEW_LIBRARIES})
message(NOTICE "GLEW_INCLUDE_DIRS " ${GLEW_INCLUDE_DIRS})


# SDL
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
Expand All @@ -33,18 +31,18 @@ message(NOTICE "GLM_INCLUDE_DIRS " ${GLM_INCLUDE_DIRS})

# Libs
set(CE_LIBS
${OPENGL_LIBRARY}
${GLEW_LIBRARIES}
${SDL2_LIBRARIES}
${OPENGL_LIBRARY}
${GLEW_LIBRARIES}
${SDL2_LIBRARIES}

PARENT_SCOPE
PARENT_SCOPE
)

#Include
set(CE_INCLUDES
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
PARENT_SCOPE
)
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
PARENT_SCOPE
)
20 changes: 10 additions & 10 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
set(NAME engine)

file(GLOB_RECURSE CE_SRC
"*.hpp"
"*.cpp"
"*.c"
"*.hpp"
"*.cpp"
"*.c"
)

add_executable(${NAME}
#WIN32
${CE_SRC})
#WIN32
${CE_SRC}
)

target_link_libraries(${NAME}
${CE_LIBS}
${CE_LIBS}
)

include_directories(${NAME}
${CMAKE_CURRENT_SOURCE_DIR}
${CE_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}
${CE_INCLUDES}
)


Expand All @@ -29,9 +30,8 @@ set_target_properties(
${NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:${NAME}>"
)

add_test(
NAME run
COMMAND ${NAME}
WORKING_DIRECTORY "$<TARGET_FILE_DIR:${NAME}>"
)
)
14 changes: 5 additions & 9 deletions engine/ce_event_handler.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@

#ifndef _CE_EVENT_HANDLER_H_
#define _CE_EVENT_HANDLER_H_
#pragma once

#include <SDL_events.h>

namespace ce {
class IEventHandler {
private:
public:
virtual void onEvent(SDL_Event& event)=0;
private:
public:
virtual void onEvent(SDL_Event& event) = 0;
};
}

#endif // _CE_EVENT_HANDLER_H_
}
7 changes: 2 additions & 5 deletions engine/ce_math.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#ifndef _CE_MATH_H_
#define _CE_MATH_H_
#pragma once

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#endif // _CE_MATH_H_
#include <glm/gtc/type_ptr.hpp>
6 changes: 3 additions & 3 deletions engine/ce_render_fundementals.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//#include <memory>
// #include <memory>

#include "rendering/mesh.h"
#include "rendering/shader.h"
#include "rendering/texture.h"
#include "rendering/vertex.h"
#include "rendering/mesh.h"
/*
#define PTR std::shared_ptr
#define PTR_CAST = dynamic_pointer_cast
#define OBJMAP(x) std::map<std::string,PTR<x>>
*/
*/
7 changes: 2 additions & 5 deletions engine/ce_rendering.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#ifndef _CE_GL_H_
#define _CE_RENDERING_H_
#pragma once

#include <GL/glew.h>
#include <SDL.h>

#endif // !_CE_GL_H_
#include <SDL.h>
19 changes: 5 additions & 14 deletions engine/core/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@

#include <ce_rendering.h>

float ce::Time::getTime()
{
return SDL_GetTicks()/1000.0f;
float ce::Time::getTime() {
return SDL_GetTicks() / 1000.0f;
}
ce::Time::Time():
m_last(getTime()),
m_now(0),
m_dt(0),
m_fps(0)
{}
ce::Time::Time() : m_last(getTime()), m_now(0), m_dt(0), m_fps(0) {}

ce::Time::~Time()
{
}
ce::Time::~Time() {}

void ce::Time::update()
{
void ce::Time::update() {
m_now = getTime();
m_dt = m_now - m_last;
m_fps = 1 / m_dt;
Expand Down
33 changes: 13 additions & 20 deletions engine/core/time.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#ifndef _CE_TIME_H_
#define _CE_TIME_H_
#pragma once

namespace ce {
class Time
{
private:
float
m_now,
m_last,
m_dt,
m_fps;
class Time {
private:
float m_now, m_last, m_dt, m_fps;

float getTime();
public:
Time();
~Time();
float getTime();

void update();
public:
Time();
~Time();

float getDeltaTime() {return m_dt;}
float getFPS() {return m_fps;};
};
}
void update();

#endif // !_CE_TIME_H_
float getDeltaTime() { return m_dt; }
float getFPS() { return m_fps; };
};
}
29 changes: 13 additions & 16 deletions engine/core/tpnt_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,35 @@
* Tumpnt Logger
* Author: Cameron Trow <[email protected]>
* Source: https://github.com/Tumpnt/TumpntAudio/blob/master/src/core/ta_log.h
*
*
* Example Usage
*
*
* int main() {
* LOG_INFO("Hello World");
* return 0;
* }
*
*
* Output:
* [INFO][main.cpp:3|main]: Hello World
*
*
*/
#ifndef _TPNT_LOG_H_
#define _TPNT_LOG_H_
#pragma once

#include <stdio.h>
#include <cstring>
#include <stdio.h>
#include <string>

#define TPNT_LOGGER_STR(X) (std::string("")+X).c_str()
#define TPNT_LOGGER_STR(X) (std::string("") + X).c_str()
#define TPNT_LOGGER_FORMAT "[%s][%s:%d|%s]: %s\n"
#define TPNT_LOGGER_FILE strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__
#define TPNT_LOGGER_CONTEXT TPNT_LOGGER_FILE,__LINE__,__FUNCTION__
#define TPNT_LOG(L,X) printf(TPNT_LOGGER_FORMAT,TPNT_LOGGER_STR(L),TPNT_LOGGER_CONTEXT,TPNT_LOGGER_STR(X))
#define TPNT_LOGGER_CONTEXT TPNT_LOGGER_FILE, __LINE__, __FUNCTION__
#define TPNT_LOG(L, X) printf(TPNT_LOGGER_FORMAT, TPNT_LOGGER_STR(L), TPNT_LOGGER_CONTEXT,TPNT_LOGGER_STR(X))
#define TPNT_LOG_RESET "\033[0m"
#define TPNT_LOG_SUCCESS "\033[1;32m"
#define TPNT_LOG_WARN "\033[1;33m"
#define TPNT_LOG_ERROR "\033[1;31m"

#define LOG_INFO(X) TPNT_LOG("INFO",X)
#define LOG_WARN(X) TPNT_LOG(TPNT_LOG_WARN+"WARN"+TPNT_LOG_RESET,X)
#define LOG_ERROR(X) TPNT_LOG(TPNT_LOG_ERROR+"ERROR"+TPNT_LOG_RESET,X)
#define LOG_SUCCESS(X) TPNT_LOG(TPNT_LOG_SUCCESS+"SUCCESS"+TPNT_LOG_RESET,X)

#endif // _TPNT_LOG_H_
#define LOG_INFO(X) TPNT_LOG("INFO", X)
#define LOG_WARN(X) TPNT_LOG(TPNT_LOG_WARN + "WARN" + TPNT_LOG_RESET, X)
#define LOG_ERROR(X) TPNT_LOG(TPNT_LOG_ERROR + "ERROR" + TPNT_LOG_RESET, X)
#define LOG_SUCCESS(X) TPNT_LOG(TPNT_LOG_SUCCESS + "SUCCESS" + TPNT_LOG_RESET, X)
53 changes: 20 additions & 33 deletions engine/core/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#include "tpnt_log.h"

ce::Window::Window(const char* title)
:m_window(NULL),
m_context(NULL),
m_mouse(true)
{

: m_window(NULL), m_context(NULL), m_mouse(true) {

/*
* Init SDL
*/
Expand All @@ -19,55 +16,45 @@ m_mouse(true)
/*
* Window Creation
*/
m_window = SDL_CreateWindow(
"Cinnabar",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1280,
720,
SDL_WINDOW_OPENGL| SDL_WINDOW_RESIZABLE
);
if(m_window==NULL)
{
m_window = SDL_CreateWindow("Cinnabar", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 1280, 720,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (m_window == NULL) {
LOG_ERROR("Failed to create GLFW window");
SDL_Quit();
exit(-1);
}
//SDL_MaximizeWindow(window);
// SDL_MaximizeWindow(window);
/*int w,h;
SDL_GetWindowSize(window,&w, &h);
WINDOW = glm::vec2(w,h);*/
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

SDL_GL_SetAttribute(
SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

setMouseVisibility(true);

m_context = SDL_GL_CreateContext(m_window);
}
ce::Window::~Window()
{
ce::Window::~Window() {
SDL_DestroyWindow(m_window);
SDL_Quit();
}
void ce::Window::swapBuffers()
{
void ce::Window::swapBuffers() {
SDL_GL_SwapWindow(m_window);
}

glm::vec2 ce::Window::getWindowSize()
{
int w,h;
SDL_GetWindowSize(m_window,&w, &h);
return glm::vec2((float)w,(float)h);
glm::vec2 ce::Window::getWindowSize() {
int w, h;
SDL_GetWindowSize(m_window, &w, &h);
return glm::vec2((float)w, (float)h);
}
float ce::Window::getAspectRatio()
{
float ce::Window::getAspectRatio() {
glm::vec2 size = getWindowSize();
return size.x/size.y;
return size.x / size.y;
}
void ce::Window::setMouseVisibility(bool enabled)
{
void ce::Window::setMouseVisibility(bool enabled) {
m_mouse = enabled;
SDL_SetRelativeMouseMode(enabled?SDL_FALSE:SDL_TRUE);
SDL_SetRelativeMouseMode(enabled ? SDL_FALSE : SDL_TRUE);
}
Loading

0 comments on commit 20becf2

Please sign in to comment.