Commit 0cdf0d38 authored by Elias Broschin's avatar Elias Broschin
Browse files

merged with develop

parents d14e5286 b34f2ca4
before_script:
- ./build_deps.sh linux
linux:
script:
- make clean
- premake5 --cc=clang gmake
- make -j 7
tags:
- Linux
only:
- develop
allow_failure: true
cmake_minimum_required(VERSION 3.1)
project(gdw_ss15_cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
#use clang instead of g++
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -stdlib=libc++")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -pedantic")
#define symbols for debug build
if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DDEBUG)
if (NOT WIN32)
add_definitions(-DSTACKTRACE)
endif ()
endif ()
#define symbols for project
add_definitions(-DGLM_SWIZZLE)
add_definitions(-DGLEW_STATIC)
find_package(OpenGL)
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/lib"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/glew/include"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/gli/gli"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/glm/glm"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2/include"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/glew/include"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/gli"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/glm"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2/include"
"${CMAKE_CURRENT_SOURCE_DIR}/lib/sdl2_mixer/x86_64-w64-mingw32/include/SDL2"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
FILE(GLOB_RECURSE clion_all_headers
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/*.inl
)
FILE (GLOB_RECURSE clion_all_headers
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/*.inl
#glew library
add_library(glew_static STATIC IMPORTED)
set_target_properties(glew_static PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib/glew/build/libGLEW.a
)
set(LINKED_LIBRARIES
SDL2
SDL2main
SDL2_mixer
GL
c++
c++abi
)
add_executable(Game ${clion_all_headers})
\ No newline at end of file
add_executable(Game ${clion_all_headers})
target_link_libraries(Game ${LINKED_LIBRARIES} glew_static)
file(COPY assets DESTINATION .)
\ No newline at end of file
# FSI-Lizenz
Copyright © 2015 Johannes Kirchner, Michael Ochmann
Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der zugehörigen Dokumentationen
(die "Software") erhält, die Erlaubnis erteilt, sie uneingeschränkt zu benutzen, inklusive und ohne Ausnahme dem Recht,
sie zu verwenden, kopieren, ändern, fusionieren, verlegen, verbreiten, unterlizenzieren und/oder zu verkaufen,
und Personen, die diese Software erhalten, diese Rechte zu geben, unter den folgenden Bedingungen:
Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in allen Kopien oder Teilkopien der Software beizulegen.
Diese Software darf niemals dazu verwendet werden, einem menschlichen Individuum, direkt oder indirekt, in irgendeiner
erdenklichen Form Schaden zuzufügen.
DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIE BEREITGESTELLT, EINSCHLIEßLICH DER GARANTIE ZUR
BENUTZUNG FÜR DEN VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER RECHTSVERLETZUNG, JEDOCH NICHT DARAUF
BESCHRÄNKT. IN KEINEM FALL SIND DIE AUTOREN ODER COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER SONSTIGE ANSPRÜCHE
HAFTBAR ZU MACHEN, OB INFOLGE DER ERFÜLLUNG EINES VERTRAGES, EINES DELIKTES ODER ANDERS IM ZUSAMMENHANG MIT DER
SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN.
\ No newline at end of file
......@@ -66,6 +66,10 @@ namespace gdw {
gdw::rendering_system& rendering_system() noexcept {
return *rendering_system_;
}
gdw::game_state_machine& game_state_machine() noexcept {
return *game_state_machine_;
}
};
}
......
#ifndef __GDW_RENDERING_SYSTEM_HPP__
#define __GDW_RENDERING_SYSTEM_HPP__
#include <vector>
#include <glm/glm.hpp>
#include <graphics/program.hpp>
......@@ -9,6 +11,7 @@
namespace gdw {
class engine;
class staticmesh_component;
}
namespace gdw {
......@@ -21,6 +24,10 @@ namespace gdw {
gdw::mesh_manager mesh_manager_;
program staticmesh_program_;
std::vector<staticmesh_component*> staticmesh_components_;
friend class staticmesh_component;
public:
rendering_system(engine& engine);
~rendering_system() = default;
......@@ -32,6 +39,7 @@ namespace gdw {
rendering_system& operator=(rendering_system&&) = default;
void update(float delta_time);
void render_gbuffer(float delta_time);
vertex_layout& staticmesh_layout() noexcept {
return staticmesh_layout_;
......@@ -40,6 +48,10 @@ namespace gdw {
gdw::mesh_manager& mesh_manager() noexcept {
return mesh_manager_;
}
private:
void register_component(staticmesh_component* component);
void unregister_component(staticmesh_component* component);
};
}
......
#ifndef __GDW_STATICMESH_COMPONENT_HPP__
#define __GDW_STATICMESH_COMPONENT_HPP__
#include <memory>
#include <ecs/component.hpp>
#include <util/id.hpp>
namespace gdw {
class engine;
class entity;
class mesh;
}
namespace gdw {
class staticmesh_component : public component {
private:
std::shared_ptr<const gdw::mesh> mesh_;
public:
staticmesh_component(engine& engine, entity& owner, const std::string& filename);
~staticmesh_component() noexcept;
staticmesh_component(const staticmesh_component&) = delete;
staticmesh_component& operator=(const staticmesh_component&) = delete;
staticmesh_component(staticmesh_component&&) = default;
staticmesh_component& operator=(staticmesh_component&&) = default;
const gdw::mesh& mesh() const {
return *mesh_;
}
static unsigned long long type_id() {
return gdw::type_id<gdw::staticmesh_component>();
}
};
}
#endif
#ifndef __GDW_COMPONENT_HELPER_HPP__
#define __GDW_COMPONENT_HELPER_HPP__
#include <vector>
namespace gdw {
template <typename t>
void remove_component(std::vector<t*>& v, t* component) {
auto it = std::find(v.begin(), v.end(), component);
if (it != v.end()) {
v.erase(it);
}
}
}
#endif
#ifndef __GDW_STACKTRACE_HPP__
#define __GDW_STACKTRACE_HPP__
#include <string>
#include <stdexcept>
namespace gdw {
extern void initStacktrace(std::string exeName);
extern bool isStacktraceAvailable();
extern std::string genStacktrace(std::size_t framesToSkip=0);
struct Error : public std::runtime_error {
explicit Error(const std::string& msg)
: std::runtime_error(msg+"\n At "+genStacktrace(1)) {}
};
}
#endif //__GDW_STACKTRACE_HPP__
\ No newline at end of file
......@@ -30,7 +30,7 @@ solution "gdw_ss15_cpp"
defines "WINDOWS"
configuration "debug"
defines "DEBUG"
defines { "DEBUG", "STACKTRACE" }
flags "Symbols"
optimize "Off"
......
......@@ -9,6 +9,7 @@ namespace gdw {
loaders_.emplace_back(make_unique<native_asset_loader>(""));
loaders_.emplace_back(make_unique<native_asset_loader>("assets/"));
loaders_.emplace_back(make_unique<native_asset_loader>("../assets/"));
loaders_.emplace_back(make_unique<native_asset_loader>("../../assets/"));
}
std::string asset_manager::native_name(const std::string& name) const {
......
......@@ -10,6 +10,7 @@
#include <ecs/entity.hpp>
#include <graphics/graphics_system.hpp>
#include <rendering/rendering_system.hpp>
#include <rendering/staticmesh_component.hpp>
#include <util/config.hpp>
#include <util/logger.hpp>
#include <util/make_unique.hpp>
......@@ -29,6 +30,9 @@ namespace gdw {
graphics_system_ = make_unique<gdw::graphics_system>(*this);
rendering_system_ = make_unique<gdw::rendering_system>(*this);
game_state_machine_ = make_unique<gdw::game_state_machine>(*this);
auto& wcube = entity_manager_.emplace_back(glm::vec3(0.f), glm::angleAxis(0.f, glm::vec3(0.f)));
wcube.emplace_back<staticmesh_component>("mesh/cube.msh");
}
engine::~engine() noexcept {
......
......@@ -23,7 +23,7 @@ game_state_machine::~game_state_machine() {
void game_state_machine::change_state(unsigned long long id) {
if(!current_state_) return;
if(current_state_->id() == id) return;
if(!Util::Map::findKey(states_, type)) return nullptr;
//if(!Util::Map::findKey(states_, type)) return nullptr;
// currentState()->onExit();
......
......@@ -4,9 +4,11 @@
#include <SDL.h>
#include <core/engine.hpp>
#include <util/stacktrace.hpp>
int main(int argc, char* argv[]) {
try {
gdw::initStacktrace(argv[0]);
gdw::engine e;
e.run();
} catch (std::exception& ex) {
......
......@@ -3,12 +3,15 @@
#include <glm/gtc/matrix_transform.hpp>
#include <core/engine.hpp>
#include <ecs/entity.hpp>
#include <graphics/graphics_system.hpp>
#include <graphics/shader.hpp>
#include <graphics/shader_manager.hpp>
#include <rendering/mesh.hpp>
#include <rendering/mesh_vertex.hpp>
#include <rendering/rendering_system.hpp>
#include <rendering/staticmesh_component.hpp>
#include <util/component_helper.hpp>
#include <util/logger.hpp>
namespace gdw {
......@@ -44,22 +47,28 @@ namespace gdw {
}
void rendering_system::update(float delta_time) {
glEnable(GL_DEPTH_TEST);
render_gbuffer(delta_time);
}
static auto toggle = true;
static std::shared_ptr<const mesh> cube;
if (toggle) {
cube = mesh_manager_.load("mesh/cube.msh");
toggle = false;
}
void rendering_system::render_gbuffer(float delta_time) {
glEnable(GL_DEPTH_TEST);
if (cube) {
staticmesh_program_.use();
staticmesh_program_.uniform("projection", false, projection_);
staticmesh_program_.uniform("view", false, view_);
cube->draw(staticmesh_program_);
staticmesh_program_.use();
staticmesh_program_.uniform("projection", false, projection_);
staticmesh_program_.uniform("view", false, view_);
for (auto sm : staticmesh_components_) {
staticmesh_program_.uniform("model", false, sm->owner().transform());
sm->mesh().draw(staticmesh_program_);
}
glDisable(GL_DEPTH_TEST);
}
void rendering_system::register_component(staticmesh_component* component) {
staticmesh_components_.emplace_back(component);
}
void rendering_system::unregister_component(staticmesh_component* component) {
remove_component(staticmesh_components_, component);
}
}
#include <asset/asset.hpp>
#include <asset/asset_manager.hpp>
#include <ecs/entity.hpp>
#include <core/engine.hpp>
#include <rendering/mesh.hpp>
#include <rendering/mesh_manager.hpp>
#include <rendering/rendering_system.hpp>
#include <rendering/staticmesh_component.hpp>
namespace gdw {
staticmesh_component::staticmesh_component(engine& engine, entity& owner, const std::string& filename)
: component(engine, owner) {
engine_.rendering_system().register_component(this);
mesh_ = engine_.rendering_system().mesh_manager().load(filename);
if (!mesh_) {
throw std::runtime_error("could not load mesh from file " + filename);
}
}
staticmesh_component::~staticmesh_component() noexcept {
engine_.rendering_system().unregister_component(this);
}
}
/**
Based on https://gist.github.com/jvranish/4441299
*/
#include "util/stacktrace.hpp"
#ifdef STACKTRACE
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#ifdef _WIN32
#include <windows.h>
#include <imagehlp.h>
#else
#include <signal.h>
#include <execinfo.h>
#endif
namespace gdw {
namespace {
void set_signal_handler();
std::string EXE_NAME;
std::string demangleStacktraceEntry(void* t) {
FILE *fp;
char var[40];
std::stringstream buffer;
#ifdef __APPLE__
buffer<<"atos -o "<<t<<" \""<<EXE_NAME<<"\"";
#else
buffer<<"addr2line -C -s -f -p "<<t<<" -e \""<<EXE_NAME<<"\"";
#endif
std::string command = buffer.str();
fp = popen(command.c_str(), "r");
buffer.str(std::string());
while (fgets(var, sizeof(var), fp) != NULL)
buffer<<var;
pclose(fp);
return buffer.str();
}
}
bool isStacktraceAvailable() {
return !EXE_NAME.empty();
}
void printStackTrace(std::string error) {
std::cerr<<error<<" at "<<genStacktrace(3)<<std::endl;
}
#ifdef _WIN32
namespace {
typedef void ( * RtlCaptureContextFunc ) ( CONTEXT * ContextRecord );
RtlCaptureContextFunc rtlCaptureContext;
}
void initStacktrace(std::string exeName) {
EXE_NAME = exeName;
HINSTANCE kernel32 = LoadLibrary("Kernel32.dll");
rtlCaptureContext = (RtlCaptureContextFunc) GetProcAddress( kernel32, "RtlCaptureContext" );
set_signal_handler();
}
namespace {
std::string windows_print_stacktrace(CONTEXT* context) {
std::stringstream ret;
SymInitialize(GetCurrentProcess(), 0, TRUE);
DWORD MachineType;
STACKFRAME64 frame;
memset(&frame, 0, sizeof(frame));
/* setup initial stack frame */
#ifdef _M_IX86
MachineType = IMAGE_FILE_MACHINE_I386;
frame.AddrPC.Offset = context->Eip;
frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context->Ebp;
frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrStack.Offset = context->Esp;
frame.AddrStack.Mode = AddrModeFlat;
#elif _M_X64
MachineType = IMAGE_FILE_MACHINE_AMD64;
frame.AddrPC.Offset = context->Rip;
frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context->Rbp;
frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrStack.Offset = context->Rsp;
frame.AddrStack.Mode = AddrModeFlat;
#elif _M_IA64
MachineType = IMAGE_FILE_MACHINE_IA64;
frame.AddrPC.Offset = context->StIIP;
frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Offset = context->IntSp;
frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrBStore.Offset= context->RsBSP;
frame.AddrBStore.Mode = AddrModeFlat;
frame.AddrStack.Offset = context->IntSp;
frame.AddrStack.Mode = AddrModeFlat;
#else
#error "Unsupported platform"
#endif
bool first = true;
while (StackWalk64( MachineType ,
GetCurrentProcess(),
GetCurrentThread(),
&frame,
context,
0,
SymFunctionTableAccess64,
SymGetModuleBase64,
0 ) ) {
if(first) first=false;
else ret<<"Called From ";
ret<<((void*)frame.AddrPC.Offset)<<": "<<demangleStacktraceEntry((void*)frame.AddrPC.Offset)<<std::endl;
}
SymCleanup( GetCurrentProcess() );
return ret.str();
}
LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo) {
switch(ExceptionInfo->ExceptionRecord->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
std::cerr<<"Error: EXCEPTION_ACCESS_VIOLATION";
break;
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
std::cerr<<"Error: EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
break;
case EXCEPTION_BREAKPOINT:
std::cerr<<"Error: EXCEPTION_BREAKPOINT";
break;
case EXCEPTION_DATATYPE_MISALIGNMENT:
std::cerr<<"Error: EXCEPTION_DATATYPE_MISALIGNMENT";
break;
case EXCEPTION_FLT_DENORMAL_OPERAND:
std::cerr<<"Error: EXCEPTION_FLT_DENORMAL_OPERAND";
break;
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
std::cerr<<"Error: EXCEPTION_FLT_DIVIDE_BY_ZERO";
break;
case EXCEPTION_FLT_INEXACT_RESULT:
std::cerr<<"Error: EXCEPTION_FLT_INEXACT_RESULT";
break;
case EXCEPTION_FLT_INVALID_OPERATION:
std::cerr<<"Error: EXCEPTION_FLT_INVALID_OPERATION";
break;
case EXCEPTION_FLT_OVERFLOW:
std::cerr<<"Error: EXCEPTION_FLT_OVERFLOW";
break;
case EXCEPTION_FLT_STACK_CHECK:
std::cerr<<"Error: EXCEPTION_FLT_STACK_CHECK";
break;
case EXCEPTION_FLT_UNDERFLOW:
std::cerr<<"Error: EXCEPTION_FLT_UNDERFLOW";
break;
case EXCEPTION_ILLEGAL_INSTRUCTION:
std::cerr<<"Error: EXCEPTION_ILLEGAL_INSTRUCTION";
break;
case EXCEPTION_IN_PAGE_ERROR:
std::cerr<<"Error: EXCEPTION_IN_PAGE_ERROR";
break;
case EXCEPTION_INT_DIVIDE_BY_ZERO:
std::cerr<<"Error: EXCEPTION_INT_DIVIDE_BY_ZERO";
break;
case EXCEPTION_INT_OVERFLOW:
std::cerr<<"Error: EXCEPTION_INT_OVERFLOW";
break;
case EXCEPTION_INVALID_DISPOSITION:
std::cerr<<"Error: EXCEPTION_INVALID_DISPOSITION";
break;
case EXCEPTION_NONCONTINUABLE_EXCEPTION:
std::cerr<<"Error: EXCEPTION_NONCONTINUABLE_EXCEPTION";
break;
case EXCEPTION_PRIV_INSTRUCTION:
std::cerr<<"Error: EXCEPTION_PRIV_INSTRUCTION";
break;
case EXCEPTION_SINGLE_STEP:
std::cerr<<"Error: EXCEPTION_SINGLE_STEP";
break;
case EXCEPTION_STACK_OVERFLOW:
std::cerr<<"Error: EXCEPTION_STACK_OVERFLOW";
break;
default:
std::cerr<<"Error: Unrecognized Exception";
break;
}
std::cerr<<" at ";
/* If this is a stack overflow then we can't walk the stack, so just show
where the error happened */
if (EXCEPTION_STACK_OVERFLOW != ExceptionInfo->ExceptionRecord->ExceptionCode)
std::cerr<<windows_print_stacktrace(ExceptionInfo->ContextRecord)<<std::endl;
else
std::cerr<<demangleStacktraceEntry((void*)ExceptionInfo->ContextRecord->Rip)<<"; Sorry, no stacktrace for windows here :-(\n Please upgrade to Linux"<<std::endl;
return EXCEPTION_EXECUTE_HANDLER;
}
void set_signal_handler() {
SetUnhandledExceptionFilter(windows_exception_handler);
}
}
std::string genStacktrace(std::size_t framesToSkip) {
std::stringstream ret;
CONTEXT context;
memset(&context, 0, sizeof(context));
context.ContextFlags = CONTEXT_CONTROL;