• Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

4E4RTS: Coding gone wrong

Sign in to follow this  


Okay, I'm running into some problems with this newly refactored map class; well, its pretty much the optimized render function.

I'm banging my head against a cement wall as I'm writing this

virtual void render(SDL_Surface* screen) {
for(int offsetX = (int)(m_offX / m_Objs.begin()->t_w); offsetX*m_Objs.begin()->t_w < m_cullX; offsetX++) {
if (offsetX > m_rows || offsetX < 0) continue;

for (int offsetY = (int)(m_offY / m_Objs.begin()->t_h); offsetY*m_Objs.begin()->t_h < m_cullY; offsetY++) {

if (offsetY > m_TileAtY || offsetY < 0) continue;

std::vector::iterator i = &m_Objs[offsetY*m_rows+offsetX];

desRect.x = offsetX * m_Objs.begin()->t_w + m_offX;
desRect.y = offsetY * m_Objs.begin()->t_h + m_offY;

srcRect.x = i->t_x; srcRect.y = i->t_y;
srcRect.w = i->t_w; srcRect.h = i->t_h;

Funnily enough, its doing weird stuff with the culling. As in, not what its supposed to be doing. Still trying to figure out what the hell I did last night. Grrr....
Sign in to follow this  


Recommended Comments

Fixed it. Apparently, throughout the whole class, I mixed up the map offsets. Stupid stupid stupid. I remember thinking "wtf" when I wrote in the map scrolling and I had to multiply the scroll speed by -1.


Fixed render function:
virtual void render(SDL_Surface* screen) {

int offsetX, offsetY;
const int t_h = m_Objs.begin()->t_h, t_w = m_Objs.begin()->t_w;
cTile* i = NULL;

for (offsetY = m_offY/t_h; offsetY < (m_offY+m_cullY)/t_h+1; offsetY++) {
if (offsetY > m_TileAtY) break;
if (offsetY < 0) continue;

for (offsetX = m_offX/t_w; offsetX < (m_offX+m_cullX)/t_w+1; offsetX++) {
if (offsetX > m_rows || offsetX < 0) break;

i = getTile(offsetX, offsetY);

desRect.x = offsetX*t_w - m_offX;
desRect.y = offsetY*t_h - m_offY;

srcRect.x = i->t_x; srcRect.y = i->t_y;
srcRect.w = i->t_w; srcRect.h = i->t_h;

SDL_BlitSurface(i->surf->surf, &srcRect, screen, &desRect);



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

  • Advertisement