#31784 - identitycrisisuk - Tue Dec 14, 2004 3:37 pm
Bit of a syntax question this, what I'm trying to do is collect together all of my data that is output into files for background maps, tiles etc. I'm starting to think that this may not be a very good way of doing it but I just wanted to create a struct I'd call LevelInfo, which would have pointers to and information about tile data etc. Then I could have an array of these for my levels and point to the relevant entry for the current level. I thought this would help clean up my code which currently has a lot of BG0[i+32*j] = SkyMap[i+Sky_WIDTH*j], if(pos.x > Level_WIDTH) etc. as I'm just using the data output by MapEd directly. As long as each background always works the same (BG0 is normal scroll, BG1 is 0.5 paralax) I could always use the same basic functions for moving around the level etc.
Here's the struct that I made to hold pointers to the data:
I then tried to initialise it like this:
from that I'm getting errors like: "error C2440: 'initializing' : cannot convert from 'const unsigned short [6400]' to 'LevelInfo'" making me think it's trying to make each variable a LevelInfo struct rather than a member of the struct. Are you allowed to put consts in a struct and if so how do you initialise them?
I tried taking away the consts in the struct definition and that gives errors like: "error C2440: 'initializing' : cannot convert from 'const unsigned short [6400]' to 'unsigned short *'", which makes more sense than the above one - it's at least trying to put the variables in properly but recognising that I'd be taking away the const nature of the original pointers by putting their address in a non const pointer. I'd never modify the content of these LevelInfo structs so is there some way I can get around this issue? Or anyone want to tell me I'm an idiot and suggest something completely different ;)
_________________
Here's the struct that I made to hold pointers to the data:
Code: |
typedef struct
{ const u16 *CollisionMap, *BG0Map, *BG1Map, *BG2Map, *BG3Map; const int BG0Width, BG0Height, BG1Width, BG1Height, BG2Width, BG2Height, BG3Width, BG3Height; const u16 *BGPalette, *BGTiles; const int BGPalettes, BGTileNum; }LevelInfo, *LevelInfoPtr; |
I then tried to initialise it like this:
Code: |
LevelInfo Level[] =
{ { bgCollision, bgMapLevel, bgMapFog, bgMapSky, 0, Level_WIDTH, Level_HEIGHT, Fog_WIDTH, Fog_HEIGHT, Sky_WIDTH, Sky_HEIGHT, 0, 0, bgPalette, bgTiles, BG_PALETTES, BG_TILES }, }; |
from that I'm getting errors like: "error C2440: 'initializing' : cannot convert from 'const unsigned short [6400]' to 'LevelInfo'" making me think it's trying to make each variable a LevelInfo struct rather than a member of the struct. Are you allowed to put consts in a struct and if so how do you initialise them?
I tried taking away the consts in the struct definition and that gives errors like: "error C2440: 'initializing' : cannot convert from 'const unsigned short [6400]' to 'unsigned short *'", which makes more sense than the above one - it's at least trying to put the variables in properly but recognising that I'd be taking away the const nature of the original pointers by putting their address in a non const pointer. I'd never modify the content of these LevelInfo structs so is there some way I can get around this issue? Or anyone want to tell me I'm an idiot and suggest something completely different ;)
_________________
Code: |
CanIKickIt(YES_YOU_CAN); |