Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 9, 2006, 06:10 PM   #1
slooksterPSV
macrumors 68030
 
Join Date: Apr 2004
Location: Nowheresville
Send a message via AIM to slooksterPSV Send a message via MSN to slooksterPSV Send a message via Yahoo to slooksterPSV
Memory Error? Allocation Error? What's going on?

I'm blitting each individual tile directly to the screen, but when I get the x coordinates of the tiles in the first 2 rows, they're huge, here's the readout of the first 27 tiles:
3515728 3515792
3516752 3516816
3517776 3517840
3518800 3518864
3519824 3519888
3520848 3520912
3521872 3521936
3522896 3522960
3523920 3523984
3524944 3525008
3525968 3526032
3526992 3527056
3528016 3528080
3529040 3529104
3530064 3530128
3531088 3531152
3532112 3532176
3533136 3533200
3534160 3534224
3535184 3535248
3536208 3536272
3537232 3537296
3538256 3538320
3539280 3539344
3540304 3540368
3541328 3541392
3542352 3542416
3543376 3543440
64 32
96 32
I'm not sure if this is a memory error or what, but each tile has an SDL_Rect which stores where the x location is at and all that. When I call the function for the first 27, its all normal, they're all just as they should be 0, 0 - 32, 0 - 64, 0. Here's some code clips:
Code:
[cLevel.h]
//Shawn Barnes
//June 3rd, 2006
#ifndef __CLEVEL_H_
#define __CLEVEL_H_

#include <iostream>
#include <fstream.h>
#include "cTile.h"

class cLevel {

private:
	SDL_Surface* m_Bitmap;
	SDL_Surface* m_Window;
	cTile *m_Tiles[];

public:
	cLevel(SDL_Surface* window, SDL_Surface* lBitmap) : m_Window(window), m_Bitmap(lBitmap)
	{
		Load("data/test.txt");
	}

	~cLevel() { }

	void Load(char* level)
	{
		int x = 0;
		int y = 0;
		ifstream input_stream(level);
		int dummy;
		int input_tile_type;
		input_stream >> wtile_width;
		input_stream >> wtile_height;
		area_width = wtile_width*TILE_WIDTH;
		area_height = wtile_height*TILE_HEIGHT;
		input_stream >> dummy;
		
		int tiletotal = wtile_width*wtile_height;
		for(int t = 0; t < tiletotal; t++)
		{
			input_stream >> input_tile_type;
			m_Tiles[t] = new cTile(m_Bitmap, x, y, (int)input_tile_type);
			x += TILE_WIDTH;
			if(x >= area_width)
			{
				x = 0;
				y += TILE_HEIGHT;
			}
		}
		input_stream.close();
	}
		
	void Draw()
	{
		int tiletotal = wtile_width*wtile_height;
		//leveltemp = SDL_DisplayFormat(m_Window);
		for(int t = 0; t < tiletotal; t++)
		{
			m_Tiles[t]->Draw(m_Window);
		}
		//SDL_UpdateRect(leveltemp, 0, 0, 0, 0);
		//SDL_BlitSurface(m_Temp, &camera, m_Window, &dest);
	}
	
	bool TestCollision(SDL_Rect obj, cPlayer* player,  Direction p_dir)
	{
		SDL_Rect temp;
		int tiletotal = wtile_width*wtile_height;
		for(int t = 0; t < tiletotal; t++)
		{
			temp = m_Tiles[t]->GetRect();
			if(m_Tiles[t]->GetType() == 2) {
				if(RectOnRectCollision(obj, temp))
				{
					return true;
				}
			}
		}
		if((obj.x < 0))
			return false;
		if((obj.x+obj.w > WINDOW_WIDTH))
			return false;
		if((obj.y < 0))
			return false;
		if((obj.y+obj.h > WINDOW_HEIGHT))
			return false;
		return false;
	}

};

#endif
Code:
[cTile.h]
//cTile by Shawn Barnes
//Date: June 3rd, 2006
//Thanks for Aaron Cox for the help

#ifndef __CTILE_H_
#define __CTILE_H_

class cTile {

private:
	int m_ImageX;
	int m_ImageY;
	int m_Width;
	int m_Height;
	int m_Type;
	int dstX;
	int dstY;
	SDL_Rect box;
	SDL_Rect tile;
	SDL_Surface* m_Tile;
	
public:
	cTile(SDL_Surface* bitmap, int dx, int dy, int type)
	{
		m_Tile = bitmap;
		dstX = dx;
		dstY = dy;
		m_Type = type;
		tile = TileTypeRect(m_Type);
		box.x = 0;
		box.y = 0;
		box.x = dx;
		box.y = dy;
		m_ImageX = tile.x;
		m_ImageY = tile.y;
		m_Width = tile.w;
		m_Height = tile.h;
		box.w = m_Width;
		box.h = m_Height;
	}
	cTile() {}
	~cTile() {  }
	
	SDL_Rect TileTypeRect(int type)
	{
		SDL_Rect tile_rect;
		
		switch(type)
		{
			case 1:
				tile_rect.x = 0;
				tile_rect.y = 0;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			case 2:
				tile_rect.x = 32;
				tile_rect.y = 0;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			case 3:
				tile_rect.x = 0;
				tile_rect.y = 32;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			case 4:
				tile_rect.x = 32;
				tile_rect.y = 32;
				tile_rect.w = TILE_WIDTH;
				tile_rect.h = TILE_HEIGHT;
			break;
			default:
			break;
		}
		
		return tile_rect;
	}
	
	int GetType()
	{
		return m_Type;
	}
	
	void SetImageLocation(int x, int y)
	{
		m_ImageX = x;
		m_ImageY = y;
	}
	
	void Draw(SDL_Surface* window)
	{
		static int x = -1;
		x++;

		if(x <= 35){
			std::cout << dstX << " " << dstY << " " << std::endl;
			}
		if(RectOnRectCollision(camera, box))
		{
			HandleUpdate(box.x-camera.x, box.y-camera.y, m_Tile, window, &tile);
		}
	}
	
	SDL_Rect GetRect()
	{
		return box;
	}
	
	bool collision;
	
};

#endif
Do you see any errors or that?
__________________
AMD Phenom 9600, 2GB RAM, 250GB HDD, ATI Radeon 4850, Vista Home Premium 64-bit
Gateway NV53 with Windows 7 Home Premium 64-bit & Ubuntu 10.04 Lucid Lynx 64-bit
slooksterPSV is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
"W" key problem on brand new macbook. What's going on? jonesjb MacBook Pro 0 Apr 21, 2010 10:21 AM
My MBP randomly turned on at 4:40 AM. What's going on? DoNoHarm MacBook Pro 14 May 13, 2009 01:28 AM
Screen saver: picture on top of another picture. What's going on? LeahM Mac Basics and Help 2 Oct 3, 2008 11:40 AM
Anyone ever get this error message. What's going on? Poncho OS X 0 Aug 22, 2008 09:50 AM
What's going on? Apple on updating products... mjstew33 Buying Tips and Advice 13 Aug 23, 2006 08:48 PM


All times are GMT -5. The time now is 05:05 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC