Sign in to follow this  
  • entries
    132
  • comments
    99
  • views
    88618

Texturing, Camera Controls, And Events

Sign in to follow this  
Driv3MeFar

145 views

Texturing and basic camera controls are in:


Well, they're sort of in. The camera doesn't yet interpolate between positions smoothly, it just jumps around. Texturing is brute forced just to see if I was calculating tex coords for the tiles correctly. I still need to implement some sort of texture manager that can take care of knowing what textures to apply to what tiles, and all that good stuff. This probably won't play nicely with my current tile batching system, since I won't be able to draw the entire map in a single draw call any more (unless every tile were to use the same texture), so that's going to need some more work. I'll probably store geometry buffers in a map, paired with textures, so that I can at least draw every tile using a certain texture in a single draw call.

The biggest thing I've gotten in to the project over the past day is my event system. At first, I wanted to write the entire thing myself, including my own implementation of delegates in C++. Then I realized that was a bad idea, and just grabbed the "fastest possible delegates" code from CodeProject. It works tremendously.

Events in the game work thusly:
A class interested in an event will register a handler to it. The way this works is the class provides a string identifier for the event it wants to handle, and a delegate function to call when the event is triggered. These are stored by the event manager in a hash map of strings to delegates.
At any time, a piece of code can trigger an event by calling EventManager::MakeEvent(string id). This will look up the identifier in the event manager's hash map, create an event with the appropriate delegate, and add the event to a queue. Once per frame (usually right before rendering), this queue is emptied and all events in it invoke their delegates. So far it works well, but I still have some doubts about the implementation (namely, how I want the event queue to be handled). Here's the code:
Event.h

#ifndef EVENT_H
#define EVENT_H

#include
#include
#include
#pragma warning(push)
#pragma warning(disable:4100)
#include "FastDelegate.h"
#include "FastDelegateBind.h"
#pragma warning(pop)

namespace ISO
{
namespace Base
{
typedef fastdelegate::FastDelegate0<> Delegate;

class Event
{
public:
Event() {}
Event(Delegate del) : d(del) {}
void Dispatch() { d(); }
private:
Delegate d;
};

class EventManager
{
public:
EventManager();
~EventManager();

template <class C>
void RegisterEventHandler(std::string id, C* delegateClass, void (C::*handler)(void))
{
Delegate d = fastdelegate::MakeDelegate(delegateClass, handler);
m_HandlerMap.insert(HandlerMap::value_type(id, d));
}

void MakeEvent(std::string id);

void DispatchEvents();

std::queue< Event > EventQueue;
private:
typedef stdext::hash_multimap HandlerMap;
HandlerMap m_HandlerMap;
};
}
}

#endif



Event.cpp

#include
#include "../Header Files/Event.h"

ISO::Base::EventManager::EventManager()
{
}

ISO::Base::EventManager::~EventManager()
{
}


void ISO::Base::EventManager::MakeEvent(std::string id)
{
std::pair iters = m_HandlerMap.equal_range(id);
for (HandlerMap::const_iterator i = iters.first; i != iters.second; ++i)
{
EventQueue.push( i->second );
}
}

void ISO::Base::EventManager::DispatchEvents()
{
while (!EventQueue.empty())
{
EventQueue.front().Dispatch();
EventQueue.pop();
}
}


Sign in to follow this  


1 Comment


Recommended Comments

Isometric FTW! [grin]

With a close view and limited camera movement I bet you could cram in a lot of detail on screen and still keep up a snappy framerate.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now