Download presentation
Presentation is loading. Please wait.
Published byMae Walters Modified over 9 years ago
1
GAM531 DPS931 – Week 2 Into the Engine
2
Last Time in GAM531… Engine Core Client Interface Operating System API Device API Engine DX11 Device GL 4.3 Device ControllerManagerModel DX11 Object GL 4.3 Object DX 11 API GL 4.3 API DX 11 API GL 4.3 API 1 m 1 1 or 1 1 or 1 1 iEngine iController iModel
3
Back to the Engine iEngine.hpp namespace Emperor { class iEngine {…}; } Engine.hpp namespace Emperor { template class Engine : public iEngine, public Singleton > {…}; }
4
The Singleton Engine DeviceMeshVertexShader Buffer TextureMaterialActorNodeBlendStateRasterizerSceneObject Controller ManagerLightCamera Engine * engine; x10,000 class Engine { static Engine* self; public: Engine() {self = this;} static Engine* getPtr() { return self; } void stuff(); }; Engine::getPtr()->stuff();
5
Our Singleton Class (hold on…) template 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 D* Singleton ::self = nullptr; template class Engine : public iEngine, public Singleton > {…}; } Engine ::getPtr()->initialize();
6
Deeper into the Engine Engine.hpp namespace Emperor { template class Engine : public iEngine, public Singleton > { SceneController sCont; ResourceController rCont; … public: iSceneController* getSceneController() {return &sCont;} iResourceController* getResourceController() {return &rCont;} }; } EngineController 1 m
7
Why do we use controllers? Convenience & Separation Resource Scene Window
8
Scene vs. Resource Statue1.obj Summoner.obj BigDude.obj
9
Into the Controller SceneController.hpp namespace Emperor { template class SceneController : public iSceneController { public: ActorManager actMan; CameraManager camMan; LightManager lgtMan; NodeManager nodMan; … }; } ControllerManager 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; }; }
10
What does a Manager Do? Hiring – Creating the object Firing – Destroying the object Keeping Tabs – Having a reference to all objects Organizing/Scheduling – Dealing with tasks that deal with all objects Damage Control – Releasing resources if they have not been released by shutdown
11
Into the Manager BaseManager.hpp template class BaseManager { protected: ArrayList objects; ArrayList activeObjects; public: BaseManager() {} virtual ~BaseManager() {…} T* createObject() {…} void removeObject(T* o) {…} void activateObject(T* o) {…} void deactivateObject(T* o) {…} }; ManagerModel 1 m #define ArrayList std::vector
12
Std::Vector 142788426 Std::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 values front() – returns first value (ref) back() – returns last value (ref) [N] (subscript) – returns the Nth value (ref) 14278842618245 begin() – returns an iterator to the beginning beg end end() – returns an iterator to the end
13
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 for(auto i = ar.begin(), end = ar.end(); i!=end; i++) { std::cout << *i; } 142788426182 i end std::vector ::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
14
Std::Iterator Cont Many STL functions use the std::iterator std::vector intvec; intvec.push_back(20); intvec.push_back(93); intvec.insert(intvec.begin() + 1, 50);//inserts between 20 and 93 intvec.erase(intvec.begin());//removes 20 from the list auto i = std::find(intvec.begin(), intvec.end(), 93); //returns iterator to the second element i = std::find(intvec.begin(), intvec.end(), 108); //returns iterator to the end of the array 2093 509350
15
Into the Manager BaseManager.hpp template class BaseManager { protected: ArrayList objects; ArrayList activeObjects; public: BaseManager() {} virtual ~BaseManager() {…} T* createObject() {…} void removeObject(T* o) {…} void activateObject(T* o) {…} void deactivateObject(T* o) {…} }; ManagerModel 1 m #define ArrayList std::vector
16
Scene vs. Resource Statue1.obj Summoner.obj BigDude.obj
17
Into the Resource Manager ResourceManager.hpp template class ResourceManager { protected: HashMap 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
18
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 values size() – returns the number of elements clear() – 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 beginning end() – returns an iterator to the end 0x1C8AHello? 0x52CEeng.exe Key (String) Value (Pointer)
19
std::map usage 0x248F template T* findOrAdd(std::map & res, const std::string& key) { if( res.find(key) == res.end()) { res[key] = new T(); } return res[key]; } int main() { std::map im; *findOrAdd(im, “Test”) = 15; *findOrAdd(im, “Snap”) = 20; *findOrAdd(im, “Test”) = 33; return 0; } Test 0x1C8ASnap Key (String) Value (Pointer) 15 20 33
20
Into the Resource Manager ResourceManager.hpp template class ResourceManager { protected: HashMap 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
21
Scene vs. Resource Statue1.obj Summoner.obj BigDude.obj
22
Engine DX11 Device GL 4.3 Device ControllerManagerModel DX11 Object GL 4.3 Object DX 11 API GL 4.3 API DX 11 API GL 4.3 API 1 m 1 1 or 1 1 or 1 1 iEngine iController iModel To Recap
23
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.