split into different projects
This commit is contained in:
parent
2dcf656af4
commit
2d9727371a
|
|
@ -381,8 +381,17 @@ Makefile
|
|||
|
||||
*.o
|
||||
|
||||
*.a
|
||||
|
||||
*.d
|
||||
|
||||
*.ninja*
|
||||
|
||||
.idea/
|
||||
|
||||
Engine-Core/lib
|
||||
Engine-Core/intermediate-files
|
||||
Editor/bin
|
||||
Editor/intermediate-files
|
||||
Game/bin
|
||||
Game/intermediate-files
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
project "Editor"
|
||||
language "C++"
|
||||
cppdialect "C++17"
|
||||
systemversion "latest"
|
||||
targetname "Editor"
|
||||
|
||||
files
|
||||
{
|
||||
"src/**.cpp",
|
||||
"include/**.h",
|
||||
"include/**.hpp",
|
||||
}
|
||||
|
||||
filter "not action:vs*"
|
||||
libdirs
|
||||
{
|
||||
corelibdir
|
||||
}
|
||||
|
||||
--visual studio--
|
||||
filter "action:vs*"
|
||||
targetdir (vs_bindir)
|
||||
objdir (vs_intdir)
|
||||
includedirs
|
||||
{
|
||||
vs_coreinclude_dir,
|
||||
"src",
|
||||
vs_include_dir,
|
||||
vs_sfmldir .. "/include",
|
||||
vs_imguidir
|
||||
}
|
||||
|
||||
libdirs
|
||||
{
|
||||
vs_corelibdir
|
||||
}
|
||||
|
||||
--not visual studio on windows--
|
||||
filter {"not action:vs*", "system:windows"}
|
||||
targetdir (bindir)
|
||||
objdir (intdir)
|
||||
includedirs
|
||||
{
|
||||
coreinclude_dir,
|
||||
"src",
|
||||
include_dir,
|
||||
sfmldir .. "/include",
|
||||
imguidir
|
||||
}
|
||||
|
||||
--windows specific settings--
|
||||
filter{"system:windows"}
|
||||
defines "SFML_STATIC"
|
||||
defines "PLATFORM_WINDOWS"
|
||||
staticruntime "off"
|
||||
|
||||
filter {"system:windows", "configurations:debug"}
|
||||
defines{"_DEBUG", "_CONSOLE"}
|
||||
|
||||
filter {"system:windows", "configurations:release"}
|
||||
defines{"NDEBUG"}
|
||||
|
||||
--linux specific settings
|
||||
filter {"system:linux"}
|
||||
targetdir (bindir)
|
||||
objdir (intdir)
|
||||
defines "PLATFORM_LINUX"
|
||||
includedirs
|
||||
{
|
||||
coreinclude_dir,
|
||||
"src",
|
||||
include_dir,
|
||||
imguidir
|
||||
}
|
||||
|
||||
links
|
||||
{
|
||||
"sfml-graphics",
|
||||
"sfml-window",
|
||||
"sfml-audio",
|
||||
"sfml-system",
|
||||
"OpenGL",
|
||||
}
|
||||
|
||||
|
||||
--config settings
|
||||
filter "configurations:debug"
|
||||
defines {"LOG_ENABLE", "GAME_DEBUG"}
|
||||
symbols "on"
|
||||
runtime "Debug"
|
||||
kind "ConsoleApp"
|
||||
links "Core-d:static"
|
||||
|
||||
filter "configurations:release"
|
||||
defines {"GAME_RELEASE"}
|
||||
optimize "Speed"
|
||||
inlining "Auto"
|
||||
symbols "off"
|
||||
runtime "Release"
|
||||
kind "WindowedApp"
|
||||
entrypoint "mainCRTStartup"
|
||||
links "Core:static"
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#include <imgui.h>
|
||||
#include <imgui-SFML.h>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "editor" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
project "Engine-Core"
|
||||
language "C++"
|
||||
cppdialect "C++17"
|
||||
systemversion "latest"
|
||||
kind "StaticLib"
|
||||
|
||||
files
|
||||
{
|
||||
"src/**.cpp",
|
||||
"include/**.h",
|
||||
"include/**.hpp",
|
||||
"vendor/imgui/imgui.cpp",
|
||||
"vendor/imgui/imgui_draw.cpp",
|
||||
"vendor/imgui/imgui_tables.cpp",
|
||||
"vendor/imgui/imgui_widgets.cpp",
|
||||
"vendor/imgui/imgui-SFML.cpp"
|
||||
}
|
||||
|
||||
--visual studio--
|
||||
filter {"action:vs*", "system:windows"}
|
||||
targetdir (vs_corelibdir)
|
||||
objdir (vs_intdir)
|
||||
includedirs
|
||||
{
|
||||
"src",
|
||||
vs_include_dir,
|
||||
vs_sfmldir .. "/include",
|
||||
vs_imguidir
|
||||
}
|
||||
|
||||
filter {"action:vs*", "configurations:debug"}
|
||||
libdirs {vs_libdebug_dir}
|
||||
|
||||
filter {"action:vs*", "configurations:release"}
|
||||
libdirs {vs_librelease_dir}
|
||||
|
||||
|
||||
--not visual studio --
|
||||
filter {"not action:vs*", "system:windows"}
|
||||
targetdir (corelibdir)
|
||||
objdir (intdir)
|
||||
includedirs
|
||||
{
|
||||
"src",
|
||||
include_dir,
|
||||
sfmldir .. "/include",
|
||||
imguidir
|
||||
}
|
||||
|
||||
--sfml lib files for windows--
|
||||
filter {"not action:vs*", "system:windows", "configurations:debug"}
|
||||
libdirs {libdebug_dir}
|
||||
|
||||
filter {"not action:vs*", "system:windows", "configurations:release"}
|
||||
libdirs {librelease_dir}
|
||||
|
||||
--windows specific settings--
|
||||
filter{"system:windows"}
|
||||
defines "SFML_STATIC"
|
||||
defines "PLATFORM_WINDOWS"
|
||||
staticruntime "off"
|
||||
|
||||
filter {"system:windows", "configurations:debug"}
|
||||
defines{"_DEBUG", "_CONSOLE"}
|
||||
links
|
||||
{
|
||||
"sfml-graphics-s-d",
|
||||
"sfml-window-s-d",
|
||||
"opengl32",
|
||||
"gdi32",
|
||||
"freetyped",
|
||||
"sfml-audio-s-d",
|
||||
"flacd",
|
||||
"vorbisencd",
|
||||
"vorbisfiled",
|
||||
"vorbisd",
|
||||
"oggd",
|
||||
"sfml-system-s-d",
|
||||
"winmm"
|
||||
}
|
||||
|
||||
filter {"system:windows", "configurations:release"}
|
||||
defines{"NDEBUG"}
|
||||
links
|
||||
{
|
||||
"sfml-graphics-s",
|
||||
"sfml-window-s",
|
||||
"opengl32",
|
||||
"gdi32",
|
||||
"freetype",
|
||||
"sfml-audio-s",
|
||||
"flac",
|
||||
"vorbisenc",
|
||||
"vorbisfile",
|
||||
"vorbis",
|
||||
"ogg",
|
||||
"sfml-system-s",
|
||||
"winmm"
|
||||
}
|
||||
|
||||
|
||||
--linux specific settings
|
||||
filter {"system:linux"}
|
||||
defines "PLATFORM_LINUX"
|
||||
targetdir (corelibdir)
|
||||
objdir (intdir)
|
||||
includedirs
|
||||
{
|
||||
"src",
|
||||
include_dir,
|
||||
imguidir
|
||||
}
|
||||
|
||||
links
|
||||
{
|
||||
"sfml-graphics",
|
||||
"sfml-window",
|
||||
"sfml-audio",
|
||||
"sfml-system",
|
||||
"OpenGL",
|
||||
}
|
||||
|
||||
|
||||
--config settings
|
||||
filter "configurations:debug"
|
||||
defines {"LOG_ENABLE", "CORE_DEBUG"}
|
||||
symbols "on"
|
||||
runtime "Debug"
|
||||
targetname "Core-d"
|
||||
|
||||
filter "configurations:release"
|
||||
defines {"CORE_RELEASE"}
|
||||
optimize "Speed"
|
||||
inlining "Auto"
|
||||
symbols "off"
|
||||
runtime "Release"
|
||||
targetname "Core"
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "utility.h"
|
||||
#include <cstddef>
|
||||
//#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace container
|
||||
{
|
||||
|
||||
using CapacityType = EntityIndex;
|
||||
using CapacityType = index_t;
|
||||
using BoolArrayType = u8;
|
||||
|
||||
template<typename T, CapacityType capacity>
|
||||
|
|
@ -81,7 +81,7 @@ public:
|
|||
bool operator!=(const_iterator other) const { return m_ptr != other.m_ptr; }
|
||||
|
||||
private:
|
||||
pointer m_ptr;
|
||||
const_pointer m_ptr;
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
@ -113,8 +113,6 @@ public:
|
|||
|
||||
pointer data() { return m_data; }
|
||||
|
||||
const_pointer cosntData() const { return m_data; }
|
||||
|
||||
reference operator[](CapacityType index) { return m_data[index]; }
|
||||
|
||||
const_reference operator[](CapacityType index) const { return m_data[index]; }
|
||||
|
|
@ -155,87 +153,56 @@ public:
|
|||
public:
|
||||
class reference
|
||||
{
|
||||
friend class Array;
|
||||
public:
|
||||
reference(data_type* ptr_in, data_type mask_in)
|
||||
: m_ptr(ptr_in)
|
||||
, m_mask(mask_in)
|
||||
{
|
||||
{ }
|
||||
|
||||
|
||||
~reference()
|
||||
{ }
|
||||
|
||||
reference(reference&) = default;
|
||||
|
||||
operator bool () const
|
||||
{ return !!(*m_ptr & m_mask); }
|
||||
|
||||
reference& operator=(bool input)
|
||||
{
|
||||
if (input == true)
|
||||
{
|
||||
*m_ptr |= m_mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
*m_ptr &= ~m_mask;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
public:
|
||||
~reference()
|
||||
{ }
|
||||
reference& operator=(const reference& other)
|
||||
{ return *this = bool(other); }
|
||||
|
||||
reference(reference&) = default;
|
||||
void flip()
|
||||
{ *m_ptr ^= m_mask; }
|
||||
|
||||
operator bool () const
|
||||
{
|
||||
return !!(*m_ptr & m_mask);
|
||||
}
|
||||
void setTrue()
|
||||
{ *m_ptr |= m_mask; }
|
||||
|
||||
reference& operator=(bool input)
|
||||
{
|
||||
switch ((int)input)
|
||||
{
|
||||
case true:
|
||||
*m_ptr |= m_mask;
|
||||
break;
|
||||
case false:
|
||||
*m_ptr &= ~m_mask;
|
||||
break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
reference& operator=(const reference& other)
|
||||
{
|
||||
return *this = bool(other);
|
||||
}
|
||||
|
||||
void flip()
|
||||
{
|
||||
*m_ptr ^= m_mask;
|
||||
}
|
||||
void setFalse()
|
||||
{ *m_ptr &= ~m_mask; }
|
||||
|
||||
private:
|
||||
data_type* const m_ptr;
|
||||
const data_type m_mask;
|
||||
};
|
||||
|
||||
|
||||
//class const_reference
|
||||
//{
|
||||
// friend class Array;
|
||||
// const_reference(const data_type* ptr_in, const data_type mask_in)
|
||||
// : m_ptr(ptr_in)
|
||||
// , m_mask(mask_in)
|
||||
// { }
|
||||
|
||||
//public:
|
||||
// ~const_reference()
|
||||
// { }
|
||||
|
||||
// const_reference(const const_reference&) = delete;
|
||||
|
||||
// operator bool () const { return !!(*m_ptr & m_mask); }
|
||||
|
||||
// const_reference& operator=(bool) = delete;
|
||||
|
||||
// const_reference& operator=(const const_reference& other) = delete;
|
||||
// const_reference& operator=(const reference& other) = delete;
|
||||
|
||||
//private:
|
||||
// const data_type* const m_ptr;
|
||||
// const data_type m_mask;
|
||||
//};
|
||||
|
||||
|
||||
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
iterator(const data_type* input, data_type index)
|
||||
iterator(data_type* input, data_type index)
|
||||
: m_ptr(input)
|
||||
, m_bitIndex(index)
|
||||
{ }
|
||||
|
|
@ -303,24 +270,16 @@ public:
|
|||
}
|
||||
|
||||
reference operator[](CapacityType index)
|
||||
{
|
||||
return reference(m_ptr + (index / 7), m_bitIndex + (index % 8));
|
||||
}
|
||||
{ return reference(m_ptr + (index / 7), m_bitIndex + (index % 8)); }
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
return reference(m_ptr, 1 << m_bitIndex);
|
||||
}
|
||||
{ return reference(m_ptr, 1 << m_bitIndex); }
|
||||
|
||||
bool operator==(const iterator& other) const
|
||||
{
|
||||
return (m_ptr == other.m_ptr) && (m_bitIndex == other.m_bitIndex);
|
||||
}
|
||||
{ return (m_ptr == other.m_ptr) && (m_bitIndex == other.m_bitIndex); }
|
||||
|
||||
bool operator!=(const iterator& other) const
|
||||
{
|
||||
return (m_ptr != other.m_ptr) || (m_bitIndex != other.m_bitIndex);
|
||||
}
|
||||
{ return (m_ptr != other.m_ptr) || (m_bitIndex != other.m_bitIndex); }
|
||||
|
||||
private:
|
||||
data_type* m_ptr;
|
||||
|
|
@ -398,7 +357,7 @@ public:
|
|||
}
|
||||
|
||||
const_reference operator[](CapacityType index) const
|
||||
{ return (m_ptr + (index / 8)) & (1 << (index % 8)); }
|
||||
{ return (*m_ptr + (index / 8)) & (1 << (index % 8)); }
|
||||
|
||||
const_reference operator*() const
|
||||
{ return *m_ptr & (1 << m_bitIndex); }
|
||||
|
|
@ -416,7 +375,7 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
Array() { m_data = new data_type[(capacity / 8) + 1]{}; }
|
||||
Array() { m_data = new data_type[(capacity / 9) + 1]{}; }
|
||||
|
||||
~Array() { delete[] m_data; }
|
||||
|
||||
|
|
@ -444,7 +403,6 @@ public:
|
|||
reference operator[](CapacityType index)
|
||||
{ return reference(m_data + (index / 8), 1 << (index % 8)); }
|
||||
|
||||
|
||||
const_reference operator[](CapacityType index) const
|
||||
{ return m_data[index / 8] & (1 << (index % 8)); }
|
||||
|
||||
|
|
@ -453,18 +411,11 @@ public:
|
|||
const_reference readAt(CapacityType index) const
|
||||
{ return m_data[index / 8] & (1 << (index % 8)); }
|
||||
|
||||
void changeAt(CapacityType index, bool input)
|
||||
{
|
||||
switch ((int)input)
|
||||
{
|
||||
case true:
|
||||
m_data[index / 8] |= (1 << (index % 8));
|
||||
break;
|
||||
case false:
|
||||
m_data[index / 8] &= ~(1 << (index % 8));
|
||||
break;
|
||||
}
|
||||
}
|
||||
void setTrueAt(CapacityType index)
|
||||
{ m_data[index / 8] |= (1 << (index % 8)); }
|
||||
|
||||
void setFalseAt(CapacityType index)
|
||||
{ m_data[index / 8] &= ~(1 << (index % 8)); }
|
||||
|
||||
iterator begin() { return iterator(m_data, 0); }
|
||||
iterator end() { return iterator(m_data + (capacity / 8), capacity % 8); }
|
||||
|
|
@ -474,7 +425,6 @@ public:
|
|||
|
||||
private:
|
||||
data_type* m_data;
|
||||
|
||||
};
|
||||
|
||||
}//namespace
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
#include "utility.h"
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
class Transform
|
||||
{
|
||||
public:
|
||||
sf::Vector2f position{};
|
||||
sf::Vector2f speed{};
|
||||
|
||||
Transform() = default;
|
||||
Transform(sf::Vector2f position_in, sf::Vector2f speed_in)
|
||||
: position(position_in)
|
||||
, speed(speed_in)
|
||||
{ }
|
||||
|
||||
};
|
||||
|
||||
// class DrawDepth
|
||||
// {
|
||||
// public:
|
||||
// DrawDepth() = default;
|
||||
// DrawDepth(u8 input)
|
||||
// : depth(input)
|
||||
// {}
|
||||
|
||||
// u8 depth{};
|
||||
// };
|
||||
|
||||
class Sprite
|
||||
{
|
||||
public:
|
||||
Sprite() = default;
|
||||
|
||||
u8 x{};
|
||||
u8 y{};
|
||||
u8 textureIndex{};
|
||||
u8 drawDepth{};
|
||||
};
|
||||
|
||||
class BoundingBox
|
||||
{
|
||||
public:
|
||||
BoundingBox() = default;
|
||||
BoundingBox(sf::FloatRect input)
|
||||
{
|
||||
x = input.position.x;
|
||||
y = input.position.y;
|
||||
sizeX = input.size.x;
|
||||
sizeY = input.size.y;
|
||||
}
|
||||
|
||||
BoundingBox(sf::Vector2f pos, sf::Vector2f size)
|
||||
{
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
sizeX = size.x;
|
||||
sizeY = size.y;
|
||||
}
|
||||
|
||||
BoundingBox(float x_in, float y_in, float sizeX_in, float sizeY_in)
|
||||
: x(x_in)
|
||||
, y(y_in)
|
||||
, sizeX(sizeX_in)
|
||||
, sizeY(sizeY_in)
|
||||
{ }
|
||||
|
||||
float x{};
|
||||
float y{};
|
||||
float sizeX{};
|
||||
float sizeY{};
|
||||
};
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility.h>
|
||||
|
||||
#include <Entities/Entity.h>
|
||||
#include <Entities/Components.h>
|
||||
#include <Entities/EntityMemoryPool.h>
|
||||
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
friend class EntityManager;
|
||||
friend class EntityMemoryPool;
|
||||
|
||||
Entity() = delete;
|
||||
Entity(index_t index_in)
|
||||
: m_index(index_in)
|
||||
{ }
|
||||
|
||||
public:
|
||||
// template<typename T>
|
||||
// bool hasComponent() const;
|
||||
|
||||
template<typename T>
|
||||
T& getComponent() const
|
||||
{ return EntityMemoryPool::instance().getComponent<T>(m_index); }
|
||||
|
||||
template<typename T>
|
||||
void addComponent(const T& data)
|
||||
{
|
||||
T& component = EntityMemoryPool::instance().getComponent<T>(m_index);
|
||||
component = data;
|
||||
}
|
||||
|
||||
size_t id() const
|
||||
{ return EntityMemoryPool::instance().getId(m_index); }
|
||||
|
||||
tag_t tag() const
|
||||
{ return EntityMemoryPool::instance().getTag(m_index); }
|
||||
|
||||
bool alive() const
|
||||
{ return EntityMemoryPool::instance().getAlive(m_index); }
|
||||
|
||||
bool visible() const
|
||||
{ return EntityMemoryPool::instance().getVisiblity(m_index); }
|
||||
|
||||
void makeVisible()
|
||||
{ EntityMemoryPool::instance().getVisiblity(m_index).setTrue(); }
|
||||
|
||||
void makeInvisible()
|
||||
{ EntityMemoryPool::instance().getVisiblity(m_index).setFalse(); }
|
||||
|
||||
void flipVisibility()
|
||||
{ EntityMemoryPool::instance().getVisiblity(m_index).flip(); }
|
||||
|
||||
void destroy()
|
||||
{ EntityMemoryPool::instance().getAlive(m_index).setFalse(); }
|
||||
private:
|
||||
index_t m_index;
|
||||
};
|
||||
|
|
@ -9,13 +9,20 @@
|
|||
class EntityManager
|
||||
{
|
||||
public:
|
||||
void update();
|
||||
int update();
|
||||
|
||||
EntityView getEntiites(Tag);
|
||||
EntityView getEntities(tag_t);
|
||||
|
||||
inline Entity player();
|
||||
|
||||
Entity addEntity(tag_t);
|
||||
|
||||
private:
|
||||
EntityIndex m_numEntitiesByTag[util::TAG_COUNT];
|
||||
u16 m_numEntities{};
|
||||
index_t m_numEntities[util::TAG_COUNT];
|
||||
index_t m_numEntitiesToAdd[util::TAG_COUNT];
|
||||
#ifdef CORE_DEBUG
|
||||
index_t m_totalEntities{};
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <Entities/Components.h>
|
||||
#include <Containers.h>
|
||||
|
|
@ -14,8 +12,9 @@ class Entity;
|
|||
using ComponentsContainer = std::tuple
|
||||
<
|
||||
container::Array<Transform, util::MAX_ENTITIES>,
|
||||
container::Array<Texture, util::MAX_ENTITIES>,
|
||||
container::Array<Sprite, util::MAX_ENTITIES>,
|
||||
container::Array<BoundingBox, util::MAX_ENTITIES>
|
||||
//container::Array<DrawDepth, util::MAX_ENTITIES>
|
||||
>;
|
||||
|
||||
class EntityMemoryPool
|
||||
|
|
@ -25,8 +24,10 @@ private:
|
|||
friend class Entity;
|
||||
|
||||
ComponentsContainer m_components;
|
||||
container::Array<Tag, util::MAX_ENTITIES> m_tags;
|
||||
container::Array<tag_t, util::MAX_ENTITIES> m_tags;
|
||||
container::Array<subtag_t, util::MAX_ENTITIES> m_subTags;
|
||||
container::Array<bool, util::MAX_ENTITIES> m_aliveStates;
|
||||
container::Array<bool, util::MAX_ENTITIES> m_visibility;
|
||||
container::Array<size_t, util::MAX_ENTITIES> m_ids;
|
||||
|
||||
private:
|
||||
|
|
@ -41,33 +42,19 @@ private:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool hasComponent(EntityIndex index) const
|
||||
{ return std::get<container::Array<T, util::MAX_ENTITIES>>(m_components)[index].active; }
|
||||
T& getComponent(index_t index)
|
||||
{ return std::get<container::Array<T, util::MAX_ENTITIES>>(m_components)[index]; }
|
||||
|
||||
template<typename T>
|
||||
T& getComponent(EntityIndex index)
|
||||
{
|
||||
return std::get<container::Array<T, util::MAX_ENTITIES>>(m_components)[index];
|
||||
}
|
||||
tag_t getTag(index_t index) const
|
||||
{ return m_tags[index]; }
|
||||
|
||||
Tag getTag(EntityIndex index) const
|
||||
{
|
||||
return m_tags[index];
|
||||
}
|
||||
auto getAlive(index_t index)
|
||||
{ return m_aliveStates[index]; }
|
||||
|
||||
bool getAlive(EntityIndex index) const
|
||||
{
|
||||
return m_aliveStates[index];
|
||||
}
|
||||
size_t getId(index_t index) const
|
||||
{ return m_ids[index]; }
|
||||
|
||||
size_t& getId(EntityIndex index)
|
||||
{
|
||||
return m_ids[index];
|
||||
}
|
||||
auto getVisiblity(index_t index)
|
||||
{ return m_visibility[index]; }
|
||||
|
||||
void removeEntity(EntityIndex index)
|
||||
{
|
||||
m_aliveStates[index] = false;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility.h>
|
||||
|
||||
class EntityManager;
|
||||
class EntityMemoryPool;
|
||||
|
||||
class Entity;
|
||||
|
||||
class EntityView
|
||||
{
|
||||
private:
|
||||
friend class EntityManager;
|
||||
friend class EntityMemoryPool;
|
||||
|
||||
EntityView() = delete;
|
||||
EntityView(index_t, index_t);
|
||||
public:
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
iterator(index_t);
|
||||
iterator& operator++();
|
||||
iterator operator++(int);
|
||||
iterator& operator--();
|
||||
iterator operator--(int);
|
||||
Entity operator*();
|
||||
Entity operator[](int);
|
||||
bool operator==(iterator);
|
||||
bool operator!=(iterator);
|
||||
private:
|
||||
index_t m_currentEntity;
|
||||
};
|
||||
|
||||
Entity operator[](index_t) const;
|
||||
|
||||
iterator begin() { return iterator(m_start); }
|
||||
iterator end() { return iterator(m_start + m_size); }
|
||||
|
||||
private:
|
||||
index_t m_start;
|
||||
index_t m_size;
|
||||
};
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
#pragma once
|
||||
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
using s8 = int8_t;
|
||||
using s16 = int16_t;
|
||||
using s32 = int32_t;
|
||||
using s64 = int64_t;
|
||||
|
||||
using tag_t = uint8_t;
|
||||
using subtag_t = uint8_t;
|
||||
|
||||
using index_t = uint16_t;
|
||||
|
||||
namespace Tag
|
||||
{
|
||||
enum : tag_t
|
||||
{
|
||||
player,
|
||||
tile,
|
||||
enemy,
|
||||
tag_count
|
||||
};
|
||||
}
|
||||
|
||||
namespace SubTag
|
||||
{
|
||||
enum : subtag_t
|
||||
{
|
||||
enemy_weak,
|
||||
enemy_strong,
|
||||
floor_tile,
|
||||
background_tile,
|
||||
subtag_count
|
||||
};
|
||||
}
|
||||
|
||||
namespace ErrorCode
|
||||
{
|
||||
enum : int
|
||||
{
|
||||
noError,
|
||||
entityOverflow,
|
||||
};
|
||||
}
|
||||
|
||||
namespace util
|
||||
{
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
inline constexpr index_t MAX_PLAYERS{1u};
|
||||
inline constexpr index_t MAX_TILES {1'000u};
|
||||
inline constexpr index_t MAX_ENEMIES {1'000u};
|
||||
inline constexpr index_t MAX_ENTITIES {MAX_PLAYERS + MAX_TILES + MAX_ENEMIES};
|
||||
inline constexpr tag_t TAG_COUNT {Tag::tag_count};
|
||||
|
||||
// used for imgui
|
||||
inline constexpr const char* tagStringsC[TAG_COUNT] =
|
||||
{
|
||||
"player",
|
||||
"tile",
|
||||
"enemy",
|
||||
};
|
||||
|
||||
inline constexpr std::string_view tagStrings[TAG_COUNT] =
|
||||
{
|
||||
"player"sv,
|
||||
"tile"sv,
|
||||
"enemy"sv,
|
||||
};
|
||||
|
||||
inline constexpr index_t tagStart[TAG_COUNT] =
|
||||
{
|
||||
0,//player
|
||||
1,//tile start
|
||||
MAX_TILES,//enemy start
|
||||
};
|
||||
|
||||
inline constexpr index_t tagSize[TAG_COUNT] =
|
||||
{
|
||||
MAX_PLAYERS,
|
||||
MAX_TILES,
|
||||
MAX_ENEMIES,
|
||||
};
|
||||
|
||||
inline constexpr index_t getTagStart(tag_t tag)
|
||||
{
|
||||
return tagStart[tag];
|
||||
}
|
||||
|
||||
inline constexpr index_t getTagSize(tag_t tag)
|
||||
{
|
||||
return tagSize[tag];
|
||||
}
|
||||
|
||||
inline constexpr const char* getTagStringC(tag_t tag)
|
||||
{
|
||||
return tagStringsC[tag];
|
||||
}
|
||||
|
||||
inline constexpr std::string_view getTagString(tag_t tag)
|
||||
{
|
||||
return tagStrings[tag];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#include "Entities/EntityView.h"
|
||||
#include "log.h"
|
||||
#include <Entities/EntityManager.h>
|
||||
#include <Entities/Entity.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <utility.h>
|
||||
|
||||
inline constexpr index_t PLAYER_INDEX = util::tagStart[Tag::player];
|
||||
|
||||
int EntityManager::update()
|
||||
{
|
||||
for(int i = 0; i < util::TAG_COUNT; i++)
|
||||
{
|
||||
if (m_numEntities[i] + m_numEntitiesToAdd[i] >= util::getTagSize(i)) [[unlikely]]
|
||||
{
|
||||
LOG("Error: Entity Overflow");
|
||||
return ErrorCode::entityOverflow;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline Entity EntityManager::player()
|
||||
{
|
||||
return Entity(PLAYER_INDEX);
|
||||
}
|
||||
|
||||
EntityView EntityManager::getEntities(tag_t tag)
|
||||
{
|
||||
return EntityView(util::getTagStart(tag), m_numEntities[tag]);
|
||||
}
|
||||
|
||||
Entity EntityManager::addEntity(tag_t tag)
|
||||
{
|
||||
#ifdef CORE_DEBUG
|
||||
m_totalEntities++;
|
||||
#endif
|
||||
|
||||
return Entity(util::tagStart[tag] + m_numEntities[tag] + m_numEntitiesToAdd[tag]++);
|
||||
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ EntityMemoryPool::EntityMemoryPool()
|
|||
EntityView x(util::tagStart[i], util::tagSize[i]);
|
||||
for (auto entity : x)
|
||||
{
|
||||
m_tags[entity.m_index] = (Tag)i;
|
||||
m_tags[entity.m_index] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
#include <Entities/EntityView.h>
|
||||
#include <Entities/Entity.h>
|
||||
#include <utility.h>
|
||||
|
||||
EntityView::EntityView(index_t start, index_t size)
|
||||
: m_start(start)
|
||||
, m_size(size)
|
||||
{ }
|
||||
|
||||
Entity EntityView::operator[](index_t index) const
|
||||
{
|
||||
return Entity(m_start + index);
|
||||
}
|
||||
|
||||
//non-const iterator
|
||||
EntityView::iterator::iterator(index_t index)
|
||||
: m_currentEntity(index)
|
||||
{ }
|
||||
|
||||
EntityView::iterator& EntityView::iterator::operator++()
|
||||
{
|
||||
m_currentEntity++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EntityView::iterator EntityView::iterator::operator++(int)
|
||||
{
|
||||
m_currentEntity++;
|
||||
return m_currentEntity - 1;
|
||||
}
|
||||
|
||||
EntityView::iterator& EntityView::iterator::operator--()
|
||||
{
|
||||
m_currentEntity--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EntityView::iterator EntityView::iterator::operator--(int)
|
||||
{
|
||||
m_currentEntity--;
|
||||
return m_currentEntity + 1;
|
||||
}
|
||||
|
||||
Entity EntityView::iterator::operator*()
|
||||
{
|
||||
return m_currentEntity;
|
||||
}
|
||||
|
||||
Entity EntityView::iterator::operator[](int index)
|
||||
{
|
||||
return m_currentEntity + index;
|
||||
}
|
||||
|
||||
bool EntityView::iterator::operator==(iterator other)
|
||||
{
|
||||
return m_currentEntity == other.m_currentEntity;
|
||||
}
|
||||
|
||||
bool EntityView::iterator::operator!=(iterator other)
|
||||
{
|
||||
return m_currentEntity != other.m_currentEntity;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue