Skip to content

Commit a33eb13

Browse files
committed
Fixes for singleplayer
1 parent 13cdc49 commit a33eb13

File tree

6 files changed

+122
-66
lines changed

6 files changed

+122
-66
lines changed

CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,10 @@ cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
22

33
project(Engine VERSION 1 LANGUAGES C CXX)
44

5-
message(${CMAKE_TOOLCHAIN_FILE})
6-
75
if (UNIX AND NOT APPLE)
86
set(LINUX TRUE)
97
endif()
108

11-
find_program(VCPKG_EXECUTABLE
12-
vcpkg PATHS "${CMAKE_CURRENT_LIST_DIR}")
13-
if (NOT VCPKG_EXECUTABLE)
14-
if (WIN32)
15-
execute_process(COMMAND "${CMAKE_CURRENT_LIST_DIR}/bootstrap-vcpkg.bat"
16-
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")
17-
else ()
18-
execute_process(COMMAND "${CMAKE_CURRENT_LIST_DIR}/bootstrap-vcpkg.sh"
19-
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")
20-
endif ()
21-
endif ()
22-
239
# Enable exception unwind semantics
2410
if(MSVC)
2511
add_compile_options("/EHsc")

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ target_include_directories(Strife.Engine
183183

184184
find_package(Vorbis REQUIRED)
185185
find_package(Torch REQUIRED)
186+
find_package(robin_hood REQUIRED)
186187

187188
target_link_libraries(Strife.Engine PUBLIC
188189
SDL2::SDL2
@@ -192,6 +193,7 @@ target_link_libraries(Strife.Engine PUBLIC
192193
OALWrapper
193194
SLikeNet
194195
Strife.ML
196+
robin_hood
195197
)
196198

197199
if(APPLE)

src/Memory/DLinkNode.hpp

Lines changed: 103 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,128 @@
11
#pragma once
22

3-
template <typename TLink>
4-
struct DLinkNode
3+
template<typename T>
4+
struct DLinkedList;
5+
6+
template<typename TElement>
7+
struct DLinkedNode
58
{
6-
DLinkNode()
7-
: next(nullptr),
8-
prev(nullptr)
9+
TElement* GetElement() { return static_cast<TElement*>(this); }
10+
TElement* GetElement() const { return static_cast<const TElement*>(this); }
11+
12+
void Unlink()
913
{
14+
if (owner != nullptr)
15+
{
16+
prev->next = next;
17+
next->prev = prev;
18+
19+
next = nullptr;
20+
prev = nullptr;
21+
}
1022
}
1123

12-
void InsertAfterThis(TLink* link)
24+
TElement* next;
25+
TElement* prev;
26+
DLinkedList<TElement>* owner;
27+
};
28+
29+
template<typename T>
30+
struct DLinkedListIterator
31+
{
32+
DLinkedListIterator(DLinkedNode<T>* node)
33+
: current(node)
1334
{
14-
link->prev = static_cast<TLink*>(this);
15-
link->next = next;
1635

17-
if (next != nullptr)
18-
next->prev = link;
36+
}
1937

20-
next = link;
38+
bool operator==(const DLinkedListIterator& rhs) const
39+
{
40+
return current == rhs.current;
2141
}
2242

23-
void InsertBeforeThis(TLink* link)
43+
bool operator!=(const DLinkedListIterator& rhs) const
2444
{
25-
link->next = static_cast<TLink*>(this);
26-
link->prev = prev;
45+
return !(*this == rhs);
46+
}
2747

28-
if (prev != nullptr)
29-
prev->next = link;
48+
T& operator*()
49+
{
50+
return current->GetElement();
51+
}
3052

31-
prev = link;
53+
DLinkedListIterator operator++()
54+
{
55+
current = current->next;
56+
return DLinkedListIterator(current);
3257
}
3358

34-
void InsertMeBetween(TLink* prev, TLink* next)
59+
DLinkedListIterator operator--()
3560
{
36-
this->next = next;
37-
this->prev = prev;
61+
current = current->prev;
62+
return DLinkedListIterator();
63+
}
3864

39-
if (next != nullptr)
40-
next->prev = static_cast<TLink*>(this);
65+
DLinkedNode<T>* current;
66+
};
4167

42-
if (prev != nullptr)
43-
prev->next = static_cast<TLink*>(this);
44-
}
68+
// A doubly-linked list implementation. It's intended to be inherited from. Note that it uses a dummy head and tail node
69+
// to simplify inserting/deleting.
70+
template<typename T>
71+
struct DLinkedList
72+
{
73+
using Node = DLinkedNode<T>;
4574

46-
void Unlink()
47-
{
48-
if (prev)
49-
prev->next = next;
75+
DLinkedList();
5076

51-
if (next)
52-
next->prev = prev;
77+
DLinkedListIterator<T> begin()
78+
{
79+
return DLinkedListIterator<T>(head.next);
80+
}
5381

54-
next = nullptr;
55-
prev = nullptr;
82+
DLinkedListIterator<T> end()
83+
{
84+
return DLinkedListIterator<T>(&tail);
5685
}
5786

58-
TLink* next;
59-
TLink* prev;
87+
void Append(Node* node);
88+
void Remove(Node* node);
89+
void InsertBefore(Node* node, Node* before);
90+
91+
Node head;
92+
Node tail;
6093
};
94+
95+
template<typename T>
96+
void DLinkedList<T>::Append(DLinkedList::Node* node)
97+
{
98+
node->owner = this;
99+
InsertBefore(&tail);
100+
}
101+
102+
template<typename T>
103+
void DLinkedList<T>::Remove(DLinkedList::Node* node)
104+
{
105+
assert(node->owner == this);
106+
}
107+
108+
template<typename T>
109+
void DLinkedList<T>::InsertBefore(Node* node, Node* before)
110+
{
111+
assert(node->owner == nullptr);
112+
113+
before->prev->next = node;
114+
node->prev = before->prev;
115+
116+
node->next = before;
117+
before->prev = node;
118+
}
119+
120+
template<typename T>
121+
DLinkedList<T>::DLinkedList()
122+
{
123+
head.next = &tail;
124+
head.prev = nullptr;
125+
126+
tail.next = nullptr;
127+
tail.prev = &head;
128+
}

src/Renderer/Renderer.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ void Renderer::RenderString(const FontSettings& fontSettings, const char* str, V
124124

125125
void Renderer::RenderRectangle(const Rectangle& rect, Color color, float depth, float angle)
126126
{
127-
// _spriteBatcher.RenderSolidColor(
128-
// color,
129-
// Vector3(
130-
// rect.topLeft.x + _renderOffset.x,
131-
// rect.topLeft.y + _renderOffset.y,
132-
// depth),
133-
// rect.Size(),
134-
// nullptr,
135-
// angle);
127+
RenderVertex v[4];
128+
Vector2 points[4];
129+
rect.GetPoints(points);
130+
131+
for (int i = 0; i < 4; ++i)
132+
{
133+
v[i].position = Vector3(points[i], depth);
134+
v[i].color = color.ToVector4();
135+
}
136+
137+
spriteEffect->RenderPolygon(v, _solidColor.get());
136138
}
137139

138140
void Renderer::RenderLine(Vector2 start, Vector2 end, Color color, float depth)

src/Renderer/TilemapRenderer.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,10 @@ void TilemapRenderer::Render(Renderer* renderer) const
9898
TileProperties* tile = tileMap[i][j];
9999
if (tile != nullptr)
100100
{
101-
// renderer->GetSpriteBatcher()->RenderSprite(
102-
// tile->sprite,
103-
// Vector3(layer.Offset() + Vector2(j, i) * tileSize, depth),
104-
// Vector2(1, 1),
105-
// 0,
106-
// false,
107-
// Color());
101+
renderer->RenderSprite(
102+
&tile->sprite,
103+
Vector2(layer.Offset() + Vector2(j, i) * tileSize),
104+
depth);
108105
}
109106
}
110107
}

src/Scene/Entity.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "Sound/SoundManager.hpp"
1818
#include "EntitySerializer.hpp"
19+
#include "Memory/DLinkNode.hpp"
1920

2021
class b2Body;
2122

@@ -63,7 +64,7 @@ struct ISyncVar;
6364
/// <summary>
6465
/// The base class of all entities. Do not inherit from this directly. Instead, use the macro <see cref="DEFINE_ENTITY"/>
6566
/// </summary>
66-
struct Entity
67+
struct Entity : DLinkedNode<Entity>
6768
{
6869
static const int InvalidEntityId = -1;
6970

0 commit comments

Comments
 (0)