Six222

Members
  • Content count

    106
  • Joined

  • Last visited

Community Reputation

453 Neutral

About Six222

  • Rank
    Member
  1. For the first question we're gonna need to see how you are creating a variable and using it... but in the second question I'm pretty sure it's crashing because (depending on how you are creating a variable of that class) SDL_CreateWindow will crash because SDL_Init hasn't been called. To be sure please show us how you are using the class and post the actual error messages please
  2. 640x512, is it safe?

      I'm not sure I've ever heard of damage being caused from changing a resolution..? Where did you see that information?
  3. Basic Rendering

    As said above you have:   bd.ByteWidth = sizeof(VERTEX) * 3;   Which sets the size of the whole vertex buffer, with this you are only able to store a maximum of 3 vertices. The error you are getting now is literally as it says, the buffer is too small to accommodate 6 vertices.
  4. Basic Rendering

    Looks like the formatting got screwed up on your code but from what I can see your doing: m_pImmediateContext->Draw(3, 0) Which only draws the first 3 vertices. It should be: m_pImmediateContext->Draw(6, 0)
  5. Events with lambdas

    Does it work that way? Each component that registers passes in it's own function to be called.. Can it capture variables from the class that triggers the event? For example   "RenderManager" registers itself to listen for event "WindowResize" and passes in function to be called when triggered.   "WindowManager" triggers "WindowResize" event with parameters w = 800, h = 600.    Can the function that "RenderManager" passes in capture the variables from "WindowManager" ?
  6. I've been playing around and trying to get to grips with some of the new C++ features and decided to do a little project using them, I really like lambdas I think they are a really great addition. However I'm having a few issues on coming up with a way to use them in an event system.   Ideally I'm trying to design a system where components can register themselves to listen for certain events and when an event is triggered these registered components are notified. My first implementation of it worked well, here's what I had: class EventManager { public: void AddListener(std::string name, std::function<void(void)> func) { events[name].push_back(func); } void TriggerEvent(std::string name) { //Error checking here for (auto it = events[name].begin(); it != events[name].end(); it++) { (*it)(); } } private: std::map<std::string, std::vector<std::function<void(void)>>> events; }; int main() { EventManager ev; auto func = []() {std::cout << "Hello world!" << std::endl; }; ev.AddListener("hello", func); ev.AddListener("hello", func); ev.TriggerEvent("hello"); system("PAUSE"); return 0; } As I said this works quite well but it's fairly basic.. Now my problem that I'm trying to solve is I'd like to be able to pass around variables. For example on a "WindowResize" event I'd like to be able to pass the new width and height to each function but still be able to maintain them in one class.   My second attempt used polymorphism to remove the limit of only being able to store std::function<void(void)>'s which looks like this: class IEvent { public: virtual void dummy() = 0; }; template<class T> class Event : public IEvent { public: Event(T t) : func(t) { } virtual void dummy() { } T func; }; class EventManager { public: void AddListener(std::string name, IEvent* func) { events[name].push_back(func); } //This is incorrect. template<class... Args> void TriggerEvent(std::string name, Args... args) { //Error checking here for (auto it = events[name].begin(); it != events[name].end(); it++) { //Call function here } } private: std::map<std::string, std::vector<IEvent*>> events; }; int main() { EventManager ev; Event<std::function<void(int, int)>> something([](int x, int y) {std::cout << "X: " << x << "Y:" << y << std::endl; }); ev.AddListener("hello", &something); ev.AddListener("hello", &something); ev.TriggerEvent("hello"); system("PAUSE"); return 0; } But I'm unable to figure out how to actually trigger the event and pass in the correct parameters. When I got to this point I realized that I can't use the variadic template in that way and that also events with different function types could be stored in the same vector which causes horrible run time errors when called... If anyone could point me in the right direction on how to "properly" do this that'd be great   Thanks.
  7. If you haven't already take a look at how Doom 3 BFG handles threads: http://fabiensanglard.net/doom3_bfg/index.php
  8. Matrix Multiplication Order

    Thanks for the great replies guys!
  9. Matrix Multiplication Order

      Ah that worked, thanks! Is there any reason why the DirectX math library uses row major and then decides to switch in HLSL to column?
  10. Matrix Multiplication Order

      That didn't work :(
  11. I have a question about matrix multiplication order in HLSL. For example in C++ I do the following: XMMATRIX matFinal = matWorld * matView * matProj; This works correctly and I just upload the final matrix to the GPU and do  position = mul(matWorld, position) But when I transfer each matrix individually and try and to the multiplication in the shader I doesn't work... Example: float4x4 matFinal = mul(mul(matWorld, matView), matProj); position = mul(matFinal, position); If anyone could explain or point me in the right direction that would be great   Thanks.
  12. I really like the look of WTL, looks much cleaner!   So I've been looking into things and found that during the window creation you can allocate extra bytes during the window creation with WNDCLASSEX.cbWndExtra. where you then create your window you can pass a pointer from CreateWindowEx() through to the lparam of the WM_CREATE message and store that pointer using SetWindowLongPtr. Then every time the in the message loop you can get that pointer with the specified HWND... Is this correct way of doing this? Example:   Thanks again for the help LRESULT CALLBACK Window::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { Window* window = (Window*)GetWindowLongPtr(hWnd, 0); switch(message) { case WM_CREATE: { CREATESTRUCT* cs = (CREATESTRUCT*) lParam; SetWindowLongPtr(hWnd, 0, (LONG_PTR) cs->lpCreateParams; } break; } } void Window::Create() { ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(Window*); //Allocate extra space for a pointer to the Window wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.lpszClassName = "GameClass"; RegisterClassEx(&wc); RECT wr = {0, 0, windowWidth, windowHeight}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); hWnd = CreateWindowEx(NULL, "GameClass", windowTitle.c_str(), WS_OVERLAPPEDWINDOW, 300, 100, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, hInstance, this); //Pass a pointer to this to WM_CREATE }