mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
more styling. TODO: finish window.hpp
This commit is contained in:
parent
c5b7a09e63
commit
bbc9af3b11
249
.clang-format
Normal file
249
.clang-format
Normal file
@ -0,0 +1,249 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
QualifierAlignment: Leave
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: true
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
PackConstructorInitializers: NextLine
|
||||
BasedOnStyle: ''
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^<ext/.*\.h>'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^<.*'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseLabels: true
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
LambdaBodyIndentation: Signature
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Left
|
||||
PPIndentWidth: -1
|
||||
RawStringFormats:
|
||||
- Language: Cpp
|
||||
Delimiters:
|
||||
- cc
|
||||
- CC
|
||||
- cpp
|
||||
- Cpp
|
||||
- CPP
|
||||
- 'c++'
|
||||
- 'C++'
|
||||
CanonicalDelimiter: ''
|
||||
BasedOnStyle: google
|
||||
- Language: TextProto
|
||||
Delimiters:
|
||||
- pb
|
||||
- PB
|
||||
- proto
|
||||
- PROTO
|
||||
EnclosingFunctions:
|
||||
- EqualsProto
|
||||
- EquivToProto
|
||||
- PARSE_PARTIAL_TEXT_PROTO
|
||||
- PARSE_TEST_PROTO
|
||||
- PARSE_TEXT_PROTO
|
||||
- ParseTextOrDie
|
||||
- ParseTextProtoOrDie
|
||||
- ParseTestProto
|
||||
- ParsePartialTestProto
|
||||
CanonicalDelimiter: pb
|
||||
BasedOnStyle: google
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
RequiresClausePosition: OwnLine
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: Never
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: Both
|
||||
Standard: Auto
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
...
|
@ -2,6 +2,7 @@
|
||||
#define ENGINE_INCLUDE_APPLICATION_H_
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -44,7 +45,6 @@ struct RenderData {
|
||||
};
|
||||
|
||||
class Application {
|
||||
|
||||
public:
|
||||
Application(const char* app_name, const char* app_version,
|
||||
gfx::GraphicsSettings graphics_settings);
|
||||
@ -55,8 +55,7 @@ public:
|
||||
/* resource stuff */
|
||||
|
||||
template <typename T>
|
||||
void RegisterResourceManager()
|
||||
{
|
||||
void RegisterResourceManager() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(resource_managers_.contains(hash) == false &&
|
||||
"Registering resource manager type more than once.");
|
||||
@ -65,15 +64,13 @@ public:
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> AddResource(const std::string& name,
|
||||
std::unique_ptr<T>&& resource)
|
||||
{
|
||||
std::unique_ptr<T>&& resource) {
|
||||
auto resource_manager = GetResourceManager<T>();
|
||||
return resource_manager->Add(name, std::move(resource));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> GetResource(const std::string& name)
|
||||
{
|
||||
std::shared_ptr<T> GetResource(const std::string& name) {
|
||||
auto resource_manager = GetResourceManager<T>();
|
||||
return resource_manager->Get(name);
|
||||
}
|
||||
@ -106,8 +103,7 @@ private:
|
||||
bool enable_frame_limiter_ = true;
|
||||
|
||||
template <typename T>
|
||||
ResourceManager<T>* GetResourceManager()
|
||||
{
|
||||
ResourceManager<T>* GetResourceManager() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
auto it = resource_managers_.find(hash);
|
||||
if (it == resource_managers_.end()) {
|
||||
@ -118,9 +114,8 @@ private:
|
||||
assert(casted_ptr != nullptr);
|
||||
return casted_ptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -21,22 +21,16 @@ public:
|
||||
|
||||
template <typename T>
|
||||
class ComponentArray : public IComponentArray {
|
||||
|
||||
public:
|
||||
void InsertData(uint32_t entity, T component)
|
||||
{
|
||||
void InsertData(uint32_t entity, T component) {
|
||||
assert(component_array_.find(entity) == component_array_.end() &&
|
||||
"Adding component which already exists to entity");
|
||||
component_array_.emplace(entity, component);
|
||||
}
|
||||
|
||||
void DeleteData(uint32_t entity)
|
||||
{
|
||||
component_array_.erase(entity);
|
||||
}
|
||||
void DeleteData(uint32_t entity) { component_array_.erase(entity); }
|
||||
|
||||
T* GetData(uint32_t entity)
|
||||
{
|
||||
T* GetData(uint32_t entity) {
|
||||
if (component_array_.contains(entity)) {
|
||||
return &(component_array_.at(entity));
|
||||
} else {
|
||||
@ -46,11 +40,9 @@ public:
|
||||
|
||||
private:
|
||||
std::map<uint32_t, T> component_array_{};
|
||||
|
||||
};
|
||||
|
||||
class System {
|
||||
|
||||
public:
|
||||
System(Scene* scene, std::set<size_t> required_component_hashes);
|
||||
virtual ~System() {}
|
||||
@ -68,7 +60,6 @@ public:
|
||||
|
||||
// entities that contain the needed components
|
||||
std::set<uint32_t> entities_{};
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -33,8 +33,7 @@ class EventQueue : public IEventQueue {
|
||||
|
||||
public:
|
||||
void Subscribe(EventSubscriberKind kind, uint32_t id,
|
||||
EventHandler<T>* handler)
|
||||
{
|
||||
EventHandler<T>* handler) {
|
||||
// For the time being, ignore kind (TODO)
|
||||
(void)kind;
|
||||
assert(subscribers_.contains(id) == false &&
|
||||
@ -42,8 +41,7 @@ public:
|
||||
subscribers_.emplace(id, handler);
|
||||
}
|
||||
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t id, T event)
|
||||
{
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t id, T event) {
|
||||
// For the time being, ignore kind (TODO)
|
||||
(void)kind;
|
||||
assert(subscribers_.contains(id) &&
|
||||
@ -52,8 +50,7 @@ public:
|
||||
event_queue_.emplace(handler, event);
|
||||
}
|
||||
|
||||
void DespatchEvents() override
|
||||
{
|
||||
void DespatchEvents() override {
|
||||
while (event_queue_.empty() == false) {
|
||||
auto [handler, event] = event_queue_.front();
|
||||
handler->OnEvent(event);
|
||||
@ -65,20 +62,16 @@ private:
|
||||
std::unordered_map<uint32_t, EventHandler<T>*> subscribers_;
|
||||
|
||||
struct QueuedEvent {
|
||||
|
||||
QueuedEvent(EventHandler<T>* handler, T event) :
|
||||
handler(handler),
|
||||
event(event) {}
|
||||
QueuedEvent(EventHandler<T>* handler, T event)
|
||||
: handler(handler), event(event) {}
|
||||
|
||||
EventHandler<T>* handler;
|
||||
T event;
|
||||
};
|
||||
std::queue<QueuedEvent> event_queue_{};
|
||||
|
||||
};
|
||||
|
||||
class EventSystem {
|
||||
|
||||
public:
|
||||
EventSystem() {}
|
||||
EventSystem(const EventSystem&) = delete;
|
||||
@ -86,8 +79,7 @@ public:
|
||||
~EventSystem() {}
|
||||
|
||||
template <typename T>
|
||||
void RegisterEventType()
|
||||
{
|
||||
void RegisterEventType() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) == false &&
|
||||
"Registering an event queue more than once!");
|
||||
@ -96,31 +88,28 @@ public:
|
||||
|
||||
template <typename T>
|
||||
void SubscribeToEventType(EventSubscriberKind kind, uint32_t id,
|
||||
EventHandler<T>* handler)
|
||||
{
|
||||
EventHandler<T>* handler) {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) &&
|
||||
"Subscribing to event type that isn't registered!");
|
||||
EventQueue<T>* queue = dynamic_cast<EventQueue<T>*>(
|
||||
event_queues_.at(hash).get());
|
||||
EventQueue<T>* queue =
|
||||
dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
|
||||
assert(queue != nullptr && "This cast should work?!! wot");
|
||||
queue->Subscribe(kind, id, handler);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t subscriber_id, T event)
|
||||
{
|
||||
void QueueEvent(EventSubscriberKind kind, uint32_t subscriber_id, T event) {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(event_queues_.contains(hash) &&
|
||||
"Subscribing to event type that isn't registered!");
|
||||
EventQueue<T>* queue = dynamic_cast<EventQueue<T>*>(
|
||||
event_queues_.at(hash).get());
|
||||
EventQueue<T>* queue =
|
||||
dynamic_cast<EventQueue<T>*>(event_queues_.at(hash).get());
|
||||
assert(queue != nullptr && "This cast should work?!! wot");
|
||||
queue->QueueEvent(kind, subscriber_id, event);
|
||||
}
|
||||
|
||||
void DespatchEvents()
|
||||
{
|
||||
void DespatchEvents() {
|
||||
for (auto& [hash, queue] : event_queues_) {
|
||||
queue->DespatchEvents();
|
||||
}
|
||||
@ -128,7 +117,6 @@ public:
|
||||
|
||||
private:
|
||||
std::unordered_map<size_t, std::unique_ptr<IEventQueue>> event_queues_{};
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -30,9 +30,7 @@ enum class MSAALevel {
|
||||
};
|
||||
|
||||
struct GraphicsSettings {
|
||||
|
||||
GraphicsSettings()
|
||||
{
|
||||
GraphicsSettings() {
|
||||
// sane defaults
|
||||
enable_validation = true;
|
||||
vsync = true;
|
||||
@ -47,7 +45,6 @@ struct GraphicsSettings {
|
||||
// (no affect with V-sync disabled)
|
||||
bool wait_for_present;
|
||||
MSAALevel msaa_level;
|
||||
|
||||
};
|
||||
|
||||
enum class ShaderType {
|
||||
@ -69,11 +66,7 @@ enum class Primitive {
|
||||
kTriangleStrip,
|
||||
};
|
||||
|
||||
enum class VertexAttribFormat {
|
||||
kFloat2,
|
||||
kFloat3,
|
||||
kFloat4
|
||||
};
|
||||
enum class VertexAttribFormat { kFloat2, kFloat3, kFloat4 };
|
||||
|
||||
enum class Filter : int {
|
||||
kLinear,
|
||||
@ -91,14 +84,12 @@ namespace ShaderStageFlags {
|
||||
kFragment = 1 << 1,
|
||||
};
|
||||
typedef std::underlying_type<Bits>::type Flags;
|
||||
}
|
||||
} // namespace ShaderStageFlags
|
||||
|
||||
struct VertexAttribDescription {
|
||||
VertexAttribDescription(uint32_t location, VertexAttribFormat format,
|
||||
uint32_t offset) :
|
||||
location(location),
|
||||
format(format),
|
||||
offset(offset) {}
|
||||
uint32_t offset)
|
||||
: location(location), format(format), offset(offset) {}
|
||||
uint32_t location; // the index to use in the shader
|
||||
VertexAttribFormat format;
|
||||
uint32_t offset;
|
||||
@ -137,10 +128,8 @@ struct SamplerInfo {
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct std::hash<engine::gfx::SamplerInfo>
|
||||
{
|
||||
std::size_t operator()(const engine::gfx::SamplerInfo& k) const
|
||||
{
|
||||
struct std::hash<engine::gfx::SamplerInfo> {
|
||||
std::size_t operator()(const engine::gfx::SamplerInfo& k) const {
|
||||
using std::hash;
|
||||
|
||||
size_t h1 = hash<int>()(static_cast<int>(k.minify));
|
||||
@ -148,9 +137,7 @@ struct std::hash<engine::gfx::SamplerInfo>
|
||||
size_t h3 = hash<int>()(static_cast<int>(k.mipmap));
|
||||
size_t h4 = hash<bool>()(k.anisotropic_filtering);
|
||||
|
||||
return ((h1 & 0xFF) << 24) |
|
||||
((h2 & 0xFF) << 16) |
|
||||
((h3 & 0xFF) << 8) |
|
||||
return ((h1 & 0xFF) << 24) | ((h2 & 0xFF) << 16) | ((h3 & 0xFF) << 8) |
|
||||
((h4 & 0xFF) << 0);
|
||||
}
|
||||
};
|
||||
|
@ -5,24 +5,17 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "window.hpp"
|
||||
#include "inputs/mouse.hpp"
|
||||
#include "inputs/keyboard.hpp"
|
||||
#include "inputs/mouse.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
enum class InputDevice : int {
|
||||
kMouse,
|
||||
kKeyboard,
|
||||
kController,
|
||||
kSize
|
||||
};
|
||||
enum class InputDevice : int { kMouse, kKeyboard, kController, kSize };
|
||||
|
||||
// This class should be used to get platform/input-device independent input
|
||||
class InputManager {
|
||||
|
||||
public:
|
||||
|
||||
/* The Window object here is stored for the duration of the InputManager.
|
||||
* 'win' must point to a valid Window object. */
|
||||
InputManager(const Window* win) : win_(win) {
|
||||
@ -36,8 +29,7 @@ public:
|
||||
~InputManager() {}
|
||||
|
||||
void AddInputButton(const std::string& name, inputs::MouseButton button) {
|
||||
AddInputDeviceButton(name, InputDevice::kMouse,
|
||||
static_cast<int>(button));
|
||||
AddInputDeviceButton(name, InputDevice::kMouse, static_cast<int>(button));
|
||||
}
|
||||
|
||||
void AddInputButton(const std::string& name, inputs::Key button) {
|
||||
@ -90,7 +82,6 @@ public:
|
||||
bool GetButtonRelease(const std::string& button_name) const;
|
||||
|
||||
private:
|
||||
|
||||
struct ButtonEntry {
|
||||
std::string name;
|
||||
enum InputDevice device;
|
||||
@ -146,7 +137,6 @@ private:
|
||||
int high, int low) {
|
||||
axis_entries_.push_back({name, device, 0, true, high, low});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -1,25 +1,24 @@
|
||||
#ifndef ENGINE_INCLUDE_LOGGER_H_
|
||||
#define ENGINE_INCLUDE_LOGGER_H_
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
|
||||
#include "log.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
// To be executed in the target application, NOT engine.dll
|
||||
void SetupLog(const char* appName) {
|
||||
|
||||
const std::string LOG_FILENAME{std::string(appName) + ".log"};
|
||||
|
||||
#ifdef NDEBUG
|
||||
// RELEASE
|
||||
const std::filesystem::path log_path{
|
||||
std::filesystem::temp_directory_path() / LOG_FILENAME};
|
||||
const std::filesystem::path log_path{std::filesystem::temp_directory_path() /
|
||||
LOG_FILENAME};
|
||||
#else
|
||||
// DEBUG
|
||||
const std::filesystem::path log_path{LOG_FILENAME};
|
||||
@ -34,8 +33,8 @@ void SetupLog(const char* appName) {
|
||||
sinks.emplace_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
|
||||
sinks.back()->set_pattern("[%H:%M:%S.%e] [%l] %v");
|
||||
|
||||
auto logger = std::make_shared<spdlog::logger>(appName, sinks.begin(),
|
||||
sinks.end());
|
||||
auto logger =
|
||||
std::make_shared<spdlog::logger>(appName, sinks.begin(), sinks.end());
|
||||
|
||||
// Logs below INFO are ignored through macros in release (see log.hpp)
|
||||
logger->set_level(spdlog::level::trace);
|
||||
@ -45,7 +44,6 @@ void SetupLog(const char* appName) {
|
||||
spdlog::flush_every(std::chrono::seconds(60));
|
||||
|
||||
LOG_INFO("Created log with path: {}", log_path.string());
|
||||
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
|
@ -16,27 +16,23 @@ public:
|
||||
|
||||
template <class T>
|
||||
class ResourceManager : public IResourceManager {
|
||||
|
||||
public:
|
||||
std::shared_ptr<T> Add(const std::string& name, std::unique_ptr<T>&& resource)
|
||||
{
|
||||
std::shared_ptr<T> Add(const std::string& name,
|
||||
std::unique_ptr<T>&& resource) {
|
||||
if (resources_.contains(name) == false) {
|
||||
std::shared_ptr<T> resource_shared(std::move(resource));
|
||||
resources_.emplace(name, resource_shared);
|
||||
return resource_shared;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw std::runtime_error("Cannot add a resource which already exists");
|
||||
}
|
||||
}
|
||||
|
||||
void AddPersistent(const std::string& name, std::unique_ptr<T>&& resource)
|
||||
{
|
||||
void AddPersistent(const std::string& name, std::unique_ptr<T>&& resource) {
|
||||
persistent_resources_.push_back(Add(name, std::move(resource)));
|
||||
}
|
||||
|
||||
std::shared_ptr<T> Get(const std::string& name)
|
||||
{
|
||||
std::shared_ptr<T> Get(const std::string& name) {
|
||||
if (resources_.contains(name)) {
|
||||
std::weak_ptr<T> ptr = resources_.at(name);
|
||||
if (ptr.expired() == false) {
|
||||
@ -54,7 +50,6 @@ private:
|
||||
std::unordered_map<std::string, std::weak_ptr<T>> resources_{};
|
||||
// This array owns persistent resources
|
||||
std::vector<std::shared_ptr<T>> persistent_resources_{};
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -14,7 +14,6 @@ namespace engine {
|
||||
class Application;
|
||||
|
||||
class Scene {
|
||||
|
||||
public:
|
||||
Scene(Application* app);
|
||||
Scene(const Scene&) = delete;
|
||||
@ -36,8 +35,7 @@ public:
|
||||
size_t GetComponentSignaturePosition(size_t hash);
|
||||
|
||||
template <typename T>
|
||||
void registerComponent()
|
||||
{
|
||||
void registerComponent() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(component_arrays_.contains(hash) == false &&
|
||||
"Registering component type more than once.");
|
||||
@ -52,15 +50,13 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetComponent(uint32_t entity)
|
||||
{
|
||||
T* GetComponent(uint32_t entity) {
|
||||
auto array = GetComponentArray<T>();
|
||||
return array->GetData(entity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* AddComponent(uint32_t entity)
|
||||
{
|
||||
T* AddComponent(uint32_t entity) {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
|
||||
auto array = GetComponentArray<T>();
|
||||
@ -71,8 +67,7 @@ public:
|
||||
auto& signature_ref = signatures_.at(entity);
|
||||
signature_ref.set(signature_position);
|
||||
|
||||
for (auto& [system_name, system] : systems_)
|
||||
{
|
||||
for (auto& [system_name, system] : systems_) {
|
||||
if (system->entities_.contains(entity)) continue;
|
||||
if ((system->signature_ & signature_ref) == system->signature_) {
|
||||
system->entities_.insert(entity);
|
||||
@ -84,8 +79,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void RegisterSystem()
|
||||
{
|
||||
void RegisterSystem() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
assert(systems_.find(hash) == systems_.end() &&
|
||||
"Registering system more than once.");
|
||||
@ -93,8 +87,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetSystem()
|
||||
{
|
||||
T* GetSystem() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
auto it = systems_.find(hash);
|
||||
if (it == systems_.end()) {
|
||||
@ -123,8 +116,7 @@ private:
|
||||
std::map<size_t, std::unique_ptr<System>> systems_{};
|
||||
|
||||
template <typename T>
|
||||
ComponentArray<T>* GetComponentArray()
|
||||
{
|
||||
ComponentArray<T>* GetComponentArray() {
|
||||
size_t hash = typeid(T).hash_code();
|
||||
auto it = component_arrays_.find(hash);
|
||||
if (it == component_arrays_.end()) {
|
||||
@ -137,7 +129,6 @@ private:
|
||||
}
|
||||
|
||||
std::unique_ptr<EventSystem> event_system_{};
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -4,15 +4,14 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "scene.hpp"
|
||||
#include "resource_manager.hpp"
|
||||
#include "scene.hpp"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class Application;
|
||||
|
||||
class SceneManager {
|
||||
|
||||
public:
|
||||
SceneManager(Application* app);
|
||||
~SceneManager();
|
||||
@ -29,7 +28,6 @@ private:
|
||||
|
||||
std::vector<std::unique_ptr<Scene>> scenes_;
|
||||
int active_scene_index_ = -1;
|
||||
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
#include <SDL.h>
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include "inputs/keyboard.hpp"
|
||||
#include "inputs/mouse.hpp"
|
||||
@ -13,7 +13,6 @@
|
||||
namespace engine {
|
||||
|
||||
class Window {
|
||||
|
||||
public:
|
||||
Window(const std::string& title, bool resizable = true,
|
||||
bool fullscreen = true);
|
||||
@ -21,72 +20,72 @@ public:
|
||||
Window& operator=(const Window&) = delete;
|
||||
~Window();
|
||||
|
||||
SDL_Window* getHandle() const;
|
||||
SDL_Window* GetHandle() const;
|
||||
|
||||
// Return the title name
|
||||
std::string getTitle() const;
|
||||
std::string GetTitle() const;
|
||||
|
||||
// Update the window state to capture any events that have occurred.
|
||||
// Run this on every frame.
|
||||
void getInputAndEvents();
|
||||
void GetInputAndEvents();
|
||||
|
||||
void setTitle(std::string title);
|
||||
void SetTitle(std::string title);
|
||||
|
||||
// Hides the window (it will appear closed to the user).
|
||||
void hide();
|
||||
void Hide();
|
||||
// Shows the window again.
|
||||
void show();
|
||||
void Show();
|
||||
// Raises the window above other windows and sets the input focus
|
||||
void focus();
|
||||
void Focus();
|
||||
// Returns true if the window has focus
|
||||
bool hasFocus() const;
|
||||
bool HasFocus() const;
|
||||
|
||||
// Sets the close flag, check this with shouldClose()
|
||||
void setCloseFlag();
|
||||
void SetCloseFlag();
|
||||
// Returns true if the window should remain open
|
||||
bool isRunning() const;
|
||||
bool IsRunning() const;
|
||||
|
||||
void setFullscreen(bool fullscreen, bool exclusive = false);
|
||||
void toggleFullscreen();
|
||||
void SetFullscreen(bool fullscreen, bool exclusive = false);
|
||||
void ToggleFullscreen();
|
||||
|
||||
bool isFullscreen() const;
|
||||
bool IsFullscreen() const;
|
||||
|
||||
// Relative mouse mode captures the cursor for FPS style use.
|
||||
// Returns false if unsupported.
|
||||
bool setRelativeMouseMode(bool enabled);
|
||||
bool SetRelativeMouseMode(bool enabled);
|
||||
|
||||
// returns true if relative mouse mode is enabled
|
||||
bool mouseCaptured();
|
||||
bool MouseCaptured();
|
||||
|
||||
// window events
|
||||
|
||||
// Returns true if the window was just resized during the previous frame
|
||||
bool getWindowResized() const;
|
||||
bool GetWindowResized() const;
|
||||
// Set the window resized flag (to recalculate aspect ratios and such)
|
||||
void setResizedFlag();
|
||||
void SetResizedFlag();
|
||||
|
||||
// keyboard events
|
||||
|
||||
// returns true if key is down
|
||||
bool getKey(inputs::Key key) const;
|
||||
bool GetKey(inputs::Key key) const;
|
||||
// returns true if key was just pressed
|
||||
bool getKeyPress(inputs::Key key) const;
|
||||
bool GetKeyPress(inputs::Key key) const;
|
||||
// returns true if key was just released
|
||||
bool getKeyRelease(inputs::Key key) const;
|
||||
bool GetKeyRelease(inputs::Key key) const;
|
||||
|
||||
// mouse events
|
||||
|
||||
// returns true if button is down
|
||||
bool getButton(inputs::MouseButton button) const;
|
||||
bool GetButton(inputs::MouseButton button) const;
|
||||
// returns true if button was just pressed
|
||||
bool getButtonPress(inputs::MouseButton button) const;
|
||||
bool GetButtonPress(inputs::MouseButton button) const;
|
||||
// returns true if button was just released
|
||||
bool getButtonRelease(inputs::MouseButton button) const;
|
||||
bool GetButtonRelease(inputs::MouseButton button) const;
|
||||
|
||||
// retrieves x coordinate of the mouse
|
||||
int getMouseX() const;
|
||||
int GetMouseX() const;
|
||||
// retrieves y coordinate of the mouse
|
||||
int getMouseY() const;
|
||||
int GetMouseY() const;
|
||||
// retrieves mouse x coordinate normalised for OpenGL
|
||||
float getMouseNormX() const;
|
||||
// retrieves mouse y coordinate normalised for OpenGL
|
||||
@ -102,8 +101,6 @@ public:
|
||||
|
||||
// joystick/gamepad events (maybe), other misc events
|
||||
|
||||
|
||||
|
||||
// returns the performance counter value in nanoseconds;
|
||||
uint64_t getNanos() const;
|
||||
// get the time recorded at the end of the last frame
|
||||
@ -124,7 +121,6 @@ public:
|
||||
static void errorBox(const std::string& message);
|
||||
|
||||
private:
|
||||
|
||||
SDL_Window* m_handle;
|
||||
|
||||
bool m_shouldClose = false;
|
||||
@ -158,11 +154,7 @@ private:
|
||||
|
||||
// input stuff
|
||||
|
||||
enum class ButtonDelta {
|
||||
SAME = 0,
|
||||
PRESSED,
|
||||
RELEASED
|
||||
};
|
||||
enum class ButtonDelta { SAME = 0, PRESSED, RELEASED };
|
||||
|
||||
struct {
|
||||
std::array<bool, SDL_NUM_SCANCODES> keys;
|
||||
@ -195,6 +187,6 @@ private:
|
||||
void onMouseWheelEvent(SDL_MouseWheelEvent& e);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user