Skip to content

Commit f11c020

Browse files
authored
Merge pull request #67 from KTStephano/v0.10
V0.10
2 parents d92ba15 + 7a681b3 commit f11c020

13 files changed

+506
-234
lines changed

README.md

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ Because of the MPL license, any community changes made to the rendering code wil
9494
| RAM | 8 GB |
9595
| GPU | Nvidia GTX 1050 Ti |
9696

97+
# Downloading Sample 3D Model Data
98+
99+
1) A zip file containing Sponza, Interrogation Room, San Miguel, Bistro, Bathroom, etc. can be found here: [https://drive.google.com/file/d/1m56T8cWMwAOHTAIbxAn-891trehgJpzH/view?usp=drive_link](https://drive.google.com/file/d/1m56T8cWMwAOHTAIbxAn-891trehgJpzH/view?usp=drive_link)
100+
101+
2) Extract the Resources.zip folder into the root of StratusGFX. It will then be at the same level as Bin/, Examples/, Source/, Tests/. Make sure that the folder structure looks like StratusGFX/Resources/* where * will be folders such as Sponza, Bistro, etc.
102+
103+
(see further down this README for a full list of credits for where the sample 3D model data came from)
104+
97105
# Building For Windows & Linux
98106

99107
This code base will currently not work on MacOS. Linux and Windows should both be fine so long as the graphics driver supports OpenGL 4.6 and the compiler supports C++17.
@@ -103,6 +111,22 @@ First set up the repo
103111
git clone --recursive https://github.com/KTStephano/StratusGFX.git
104112
cd StratusGFX
105113

114+
## Option 1: Standard Build
115+
116+
This is the preferred build if all you want to do is build the examples and run them.
117+
118+
python3 ./build_examples.py --assimp
119+
120+
-> LINUX NOTE: If you get an error during the assimp build of the above step, use your local package manager to install assimp instead. Then re-run the above step as:
121+
122+
python3 ./build_examples.py
123+
124+
Now you should be able to go into the StratusGFX/Bin/ folder and run the examples!
125+
126+
## Option 2: Development Build
127+
128+
Use this if you plan to make source code changes to anything in Examples/ Source/ or Tests/. You will only need to build the dependencies once and then after that you can just re-run the cmake build step any time you make changes.
129+
106130
Build 3rd party dependencies -> should only need to do this once per clone
107131

108132
python3 ./dependency_build.py --assimp
@@ -115,40 +139,30 @@ Now build the StratusGFX source
115139

116140
### Windows
117141

118-
cmake -Bbuild -S. -DBUILD_TESTS=OFF
142+
cmake -Bbuild -S. -DBUILD_TESTS=ON
119143
cmake --build build/ -j 8 --config RelWithDebInfo
120144

121145
### Linux
122146

123-
cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=OFF
147+
cmake -Bbuild -S. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON
124148
cmake --build build/ -j 8
125149

126-
All executables will be put into StratusGFX/Bin. Make sure you run them while inside Bin/. Good ones to run to see if it worked are
150+
All executables will be put into StratusGFX/Bin folder. Make sure you run them while inside StratusGFX/Bin/. Good ones to run to see if it worked are
127151

128152
Ex00_StartupShutdown.exe (runs through initialize, run one frame, shutdown sequence)
129153
Ex01_StratusGFX.exe (you should see a forest of red cubes since textures aren't bundled with source)
130154
StratusEngineUnitTests.exe
131155
StratusEngineIntegrationTests.exe
132156

133-
# First Places to Look
134-
135-
You can check [High Level Architecture Overview](https://ktstephano.github.io/rendering/stratusgfx/architecture), or you can start by looking through the code under Examples/ExampleEnv00 and Examples/ExampleEnv01. They both depend on code that is inside of Examples/Common which is another good place to look around.
136-
137-
None of the test scenes are bundled with this source so the rest of the environments will be completely blank when running.
138-
139-
# Running Example Environments 2-7
140-
141-
When starting the examples will take a bit to load/process. You can see the status in the console. After starting you may experience some temporary frame drops but this will stabilize quickly.
142-
143-
-> More in depth explanation here: [Examples](https://github.com/KTStephano/StratusGFX/wiki/Examples)
157+
# Running The Examples
144158

145-
1) A zip file containing Sponza, Interrogation Room, San Miguel, Bistro and Bathroom can be found here: [https://drive.google.com/file/d/1m56T8cWMwAOHTAIbxAn-891trehgJpzH/view?usp=drive_link](https://drive.google.com/file/d/1m56T8cWMwAOHTAIbxAn-891trehgJpzH/view?usp=drive_link)
159+
If you are having trouble with the downloading of the 3D assets or running the examples, a good place to check is here:
146160

147-
2) Extract the Resources.zip folder into the root of StratusGFX. It will then be at the same level as Bin/, Examples/, Source/, Tests/. Make sure that the folder structure looks like StratusGFX/Resources/* where * will be folders such as Sponza, Bistro, etc.
161+
[https://github.com/KTStephano/StratusGFX/wiki/Examples](https://github.com/KTStephano/StratusGFX/wiki/Examples)
148162

149-
3) Change directory into Bin/ and run the example environments.
163+
If this does not help then feel free to send me an email (jtstephano@gmail.com) or open an issue.
150164

151-
Example environment 01 will still be a forest of red cubes since its textures and models aren't part of the bundle.
165+
# Credits For 3D Assets Used In Examples
152166

153167
Credits for the 3D assets used in the examples/demos are as follows:
154168

@@ -168,6 +182,12 @@ Credits for the 3D assets used in the examples/demos are as follows:
168182

169183
[Abandoned Warehouse](https://sketchfab.com/3d-models/abandoned-warehouse-1e40d433ed6f48fb880a0d2172aff7ca)
170184

185+
# First Places to Look
186+
187+
You can check [High Level Architecture Overview](https://ktstephano.github.io/rendering/stratusgfx/architecture), or you can start by looking through the code under Examples/ExampleEnv00 and Examples/ExampleEnv01. They both depend on code that is inside of Examples/Common which is another good place to look around.
188+
189+
None of the test scenes are bundled with this source so the rest of the environments will be completely blank when running.
190+
171191
# Controls For Example Environments
172192

173193
WASD to move
@@ -182,4 +202,4 @@ E toggles directional light
182202

183203
G toggles global illumination
184204

185-
R recompiles all shaders
205+
R recompiles all shaders

Source/Engine/StratusCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <exception>
1111
#include <stdexcept>
1212
#include <functional>
13+
#include "StratusPointer.h"
1314

1415
#define BITMASK64_POW2(offset) (1ull << offset)
1516
#define BITMASK_POW2(offset) (1 << offset)

Source/Engine/StratusEntity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace stratus {
1111

1212
EntityPtr Entity::Create(EntityComponentSet * ptr) {
1313
if (ptr != nullptr) {
14-
return ThreadSafePoolAllocator<Entity>::AllocateSharedCustomConstruct(PlacementNew_<EntityComponentSet *>, ptr);
14+
return ThreadSafeSmartPoolAllocator<Entity>::AllocateSharedCustomConstruct(PlacementNew_<EntityComponentSet *>, ptr);
1515
}
16-
return ThreadSafePoolAllocator<Entity>::AllocateSharedCustomConstruct(PlacementNew_<>);
16+
return ThreadSafeSmartPoolAllocator<Entity>::AllocateSharedCustomConstruct(PlacementNew_<>);
1717
}
1818

1919
void EntityComponent::MarkChanged() {

Source/Engine/StratusEntity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ComponentAllocator_<Component>& GetComponentAllocator_() {
5353
static name * Create(const Types& ... args) { \
5454
auto& allocator = GetComponentAllocator_<name>(); \
5555
auto ul = std::unique_lock(allocator.m); \
56-
return allocator.allocator.Allocate(args...); \
56+
return allocator.allocator.AllocateConstruct(args...); \
5757
} \
5858
static void Destroy(name * ptr) { \
5959
if (ptr == nullptr) return; \

Source/Engine/StratusPointer.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#pragma once
2+
3+
#include <cstddef>
4+
5+
namespace stratus {
6+
template<typename T>
7+
struct DefaultUnsafePtrDeleter_ {
8+
static void DestroyAndDeallocate(T * ptr) {
9+
delete ptr;
10+
}
11+
};
12+
13+
template<typename T, typename Deleter>
14+
struct UnsafePtrControlBlock_ {
15+
Deleter deleter;
16+
size_t refcount = 1;
17+
T * ptr = nullptr;
18+
19+
UnsafePtrControlBlock_(T * ptr, Deleter deleter)
20+
: ptr(ptr), deleter(deleter) {}
21+
};
22+
23+
// Lightweight reference-counted thread-unsafe pointer wrapper
24+
template<typename T, typename Deleter = DefaultUnsafePtrDeleter_<T>>
25+
class UnsafePtr final {
26+
UnsafePtr(UnsafePtrControlBlock_<T, Deleter> * control)
27+
: control_(control) {}
28+
29+
public:
30+
UnsafePtr() {}
31+
32+
UnsafePtr(T * ptr, Deleter deleter = Deleter()) {
33+
if (ptr == nullptr) return;
34+
35+
control_ = new UnsafePtrControlBlock_<T, Deleter>(ptr, deleter);
36+
}
37+
38+
UnsafePtr(const UnsafePtr& other) {
39+
if (other.control_ == nullptr) return;
40+
control_ = other.control_;
41+
control_->refcount++;
42+
}
43+
44+
UnsafePtr(UnsafePtr&& other) {
45+
control_ = other.control_;
46+
other.control_ = nullptr;
47+
}
48+
49+
UnsafePtr& operator=(const UnsafePtr& other) {
50+
if (operator==(other)) return *this;
51+
52+
Reset();
53+
control_ = other.control_;
54+
other.control_->refcount++;
55+
56+
return *this;
57+
}
58+
59+
UnsafePtr& operator=(UnsafePtr&& other) {
60+
if (operator==(other)) return *this;
61+
62+
Reset();
63+
control_ = other.control_;
64+
other.control_ = nullptr;
65+
66+
return *this;
67+
}
68+
69+
~UnsafePtr() {
70+
Reset();
71+
}
72+
73+
bool operator==(const UnsafePtr& other) const {
74+
return control_ == other.control_;
75+
}
76+
77+
bool operator!=(const UnsafePtr& other) const {
78+
return !(operator==(other));
79+
}
80+
81+
bool operator==(std::nullptr_t) const {
82+
return control_ == nullptr;
83+
}
84+
85+
bool operator!=(std::nullptr_t) const {
86+
return !(operator==(nullptr));
87+
}
88+
89+
operator bool() const {
90+
return control_ != nullptr;
91+
}
92+
93+
T& operator*() {
94+
return *(control_->ptr);
95+
}
96+
97+
const T& operator*() const {
98+
return *(control_->ptr);
99+
}
100+
101+
T * operator->() {
102+
return control_->ptr;
103+
}
104+
105+
const T * operator->() const {
106+
return control_->ptr;
107+
}
108+
109+
T * Get() {
110+
return control_ == nullptr ? nullptr : control_->ptr;
111+
}
112+
113+
const T * Get() const {
114+
return control_ == nullptr ? nullptr : control_->ptr;
115+
}
116+
117+
void Reset() {
118+
if (control_ == nullptr) return;
119+
120+
control_->refcount--;
121+
if (control_->refcount == 0) {
122+
auto ptr = control_->ptr;
123+
control_->deleter.DestroyAndDeallocate(ptr);
124+
125+
delete control_;
126+
}
127+
control_ = nullptr;
128+
}
129+
130+
size_t RefCount() const {
131+
return control_ == nullptr ? 0 : control_->refcount;
132+
}
133+
134+
template<typename E, typename ... Args>
135+
friend UnsafePtr<E> MakeUnsafe(Args&&... args);
136+
137+
private:
138+
UnsafePtrControlBlock_<T, Deleter> * control_ = nullptr;
139+
};
140+
141+
template<typename E, typename ... Args>
142+
UnsafePtr<E> MakeUnsafe(Args&&... args) {
143+
auto ptr = new E(std::forward<Args>(args)...);
144+
return UnsafePtr<E>(new UnsafePtrControlBlock_(ptr, DefaultUnsafePtrDeleter_<E>()));
145+
}
146+
147+
static_assert(sizeof(UnsafePtr<int>) == sizeof(void *));
148+
}

0 commit comments

Comments
 (0)