gam531 dps931 – week 2 into the engine. last time in gam531… engine core client interface...
TRANSCRIPT
GAM531DPS931 – Week 2Into the Engine
Last Time in GAM531…
Engine
Core
Client Interfac
e
Operating
System API
Device API
Engine
DX11 Devic
e
GL 4.3
Device
Controller
Manager
Model
DX11 Objec
t
GL 4.3
Object
DX 11 API
GL 4.3 API
DX 11 API
GL 4.3 API
1 m
1 m
1 m
1 1 or1
1 or 1
1
iEngine
iController iModel
Back to the Engine
iEngine.hpp
namespace Emperor { class iEngine {…}; }
Engine.hpp
namespace Emperor { template <RenderSystem RS> class Engine : public iEngine, public Singleton<Engine<RS>> {…}; }
The Singleton
Engine
Device
Mesh
Vertex
Shader
Buffer
TextureMaterial
Actor
Node
BlendState
RasterizerSceneObje
ct
Controller
Manager
Light
Camera
Engine<RS>* engine; x10,000
class Engine { static Engine* self; public: Engine() {self = this;} static Engine* getPtr() { return self; } void stuff();};
Engine::getPtr()->stuff();
Static Variables
Our Singleton Class (hold on…) template <class D> class Singleton { private: static D* self; protected: public: Singleton() { if(!self) self = (D*)this; else EMP_FATAL_ERROR(“…"); } virtual ~Singleton() {self = 0;}
static D* getPtr() {return self;} };
template <class D> D* Singleton<D>::self = nullptr;
template <RenderSystem RS>class Engine : public iEngine,
public Singleton<Engine<RS>> {…}; }
Engine<RS>::getPtr()->initialize();
Deeper into the Engine
Engine.hpp
namespace Emperor { template <RenderSystem RS> class Engine : public iEngine, public Singleton<Engine<RS>> { SceneController<RS> sCont; ResourceController<RS> rCont; … public: iSceneController* getSceneController() {return &sCont;} iResourceController* getResourceController() {return &rCont;} }; }
Engine
Controller
1 m
Why do we use controllers?
Convenience& Separation
Resource SceneWindow
Scene vs. Resource
Statue1.obj
Summoner.objBigDude.obj
Into the ControllerSceneController.hpp
namespace Emperor { template <RenderSystem RS> class SceneController : public iSceneController { public: ActorManager<RS> actMan; CameraManager<RS> camMan; LightManager<RS> lgtMan; NodeManager<RS> nodMan; … }; }
Controller
Manager
1 m
iSceneController.hpp
namespace Emperor { … class iSceneController { … public: virtual iActor* createActor() = 0; virtual iCamera* createCamera() = 0; virtual iLight* createLight() = 0; virtual iNode* createNode() = 0; };
}
What does a Manager Do?
Hiring – Creating the object
Firing – Destroying the object
Keeping Tabs – Having a reference to all objectsOrganizing/Scheduling – Dealing with tasks that deal with all objectsDamage Control – Releasing resources if they have not been released by shutdown
Into the Manager
BaseManager.hpp
template <class T> class BaseManager { protected: ArrayList<T*> objects; ArrayList<T*> activeObjects; public: BaseManager() {} virtual ~BaseManager() {…} T* createObject() {…} void removeObject(T* o) {…} void activateObject(T* o) {…} void deactivateObject(T* o) {…} };
Manager
Model1 m
#define ArrayList std::vector
Std::Vector
142 78 84 26Std::Vector is a dynamic array
Common Functions:
push_back(T) – add a value to the back pop_back() – removes the last value
size() – returns the number of valuesfront() – returns first value (ref)
back() – returns last value (ref)
[N] (subscript) – returns the Nth value (ref)
142 78 84 26 182 45
begin() – returns an iterator to the beginning
beg end
end() – returns an iterator to the end
Std::Iterator
Std::Iterator is a unified method of iterating over many STL data structures
//iterating over a std::vector//assume ar is a std::vector<int>for(auto i = ar.begin(), end = ar.end(); i!=end; i++) { std::cout << *i;}
142 78 84 26 182
i end
std::vector<int>::iterator i = ar.begin();i += 3;std::cout << i – ar.begin(); //outputs 3
auto i = ar.begin();ar.push_back(25);std::cout << *i; //throws exception, iterator not valid
Std::Iterator Cont
Many STL functions use the std::iterator
std::vector<int> intvec;intvec.push_back(20);intvec.push_back(93);
intvec.insert(intvec.begin() + 1, 50);//inserts between 20 and 93intvec.erase(intvec.begin());//removes 20 from the list
auto i = std::find(intvec.begin(), intvec.end(), 93);//returns iterator to the second elementi = std::find(intvec.begin(), intvec.end(), 108);//returns iterator to the end of the array
20 93 93509350
Into the Manager
BaseManager.hpp
template <class T> class BaseManager { protected: ArrayList<T*> objects; ArrayList<T*> activeObjects; public: BaseManager() {} virtual ~BaseManager() {…} T* createObject() {…} void removeObject(T* o) {…} void activateObject(T* o) {…} void deactivateObject(T* o) {…} };
Manager
Model1 m
#define ArrayList std::vector
Scene vs. Resource
Statue1.obj
Summoner.objBigDude.obj
Into the Resource Manager
ResourceManager.hpp
template <class T>class ResourceManager { protected: HashMap<String, T*> resources; virtual T* createResource(const String& r) = 0; public: ResourceManager() {} virtual ~ResourceManager() {…} T* newResource(const String& r) {…} T* getResource(const String& resource) {…} void removeResource(T* a) {…}};
#define HashMap std::map
std::map
0x248F
std::map is an associative container (key-value pairs) which relies on unique keys
Common Functions:
insert(KEY,VALUE) – insert key and value
erase(KEY) – removes key and associated valuessize() – returns the number of elementsclear() – empties the container
find(KEY) – returns an iterator to the element
[KEY] (subscript) – returns the value associated with the key (ref)
test.obj
begin() – returns an iterator to the beginningend() – returns an iterator to the end
0x1C8AHello?
0x52CEeng.exe
Key(String
)
Value(Pointer
)
std::map usage
0x248F
template<class T>T* findOrAdd(std::map<std::string,T*>& res, const std::string& key) { if(res.find(key) == res.end()) { res[key] = new T(); } return res[key];}int main() { std::map<std::string, int> im;
*findOrAdd(im, “Test”) = 15; *findOrAdd(im, “Snap”) = 20; *findOrAdd(im, “Test”) = 33; return 0;}
Test
0x1C8ASnap
Key(String
)
Value(Pointer
)15
20
33
Into the Resource Manager
ResourceManager.hpp
template <class T>class ResourceManager { protected: HashMap<String, T*> resources; virtual T* createResource(const String& r) = 0; public: ResourceManager() {} virtual ~ResourceManager() {…} T* newResource(const String& r) {…} T* getResource(const String& resource) {…} void removeResource(T* a) {…}};
#define HashMap std::map
Scene vs. Resource
Statue1.obj
Summoner.objBigDude.obj
Engine
DX11 Devic
e
GL 4.3
Device
Controller
Manager
Model
DX11 Objec
t
GL 4.3
Object
DX 11 API
GL 4.3 API
DX 11 API
GL 4.3 API
1 m
1 m
1 m
1 1 or1
1 or 1
1
iEngine
iController iModel
To Recap
To Do• Create zenit wiki accounts if you don’t already have one
• Add your user information to the student list on the wiki
• Read over Assignment 1 (will be released Friday)
• Begin to look for group partners (2-3 per group)
• Bookmark the GAM531 website
• Make an account on Bit Bucket