Help with programming problem.


mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
Hey, I need to draw tile[sector][XYZ value]. Currently I have tile[random order][XYZ value].


In the second element I have 5 slots as follows,


[0] = Xposition


[1] = Y position


[2] = Texture


[3] = SECTOR


[4] = Layer


Im rendering 2D graphics, Layer describes wich parralax layer the tile should be drawn on.


SECTOR is the way I broke down the graphics to not go through all the tiles in a map when rendering but only go through max X amount of tiles, one sector is a screen big, 800x480, and at rendering I want to draw 9 of them, the sector grid layout is Y+1, X+50. Forming a 50x50 screens square grid.


My rendering I want to do this basically, draw tile[current_sector][X] and tile[current_sector-1] and current sector+1, and current_sector +49, +50, +51, -49,-50,-51.


But I need to make a new array or some sort of way to be able to do that. Each tile has its link to a sector its inside in the second element.


I could resort the tiles into a new giant array, but that would waste a LOT of ram since not every sector is full of graphics and infact most sectors may not have any tiles in them at all.


I want to make a system of only creating arrays as large as needed, I can get the number of tiles per sector. But I also need to be able to render a sector with 0 tiles in it, it still needs to be processed for the rendering function to work.


I include the source files Im working on but the engine is a mess, hopefully the editor is clear enough to get a better picture of what I want. Well in the engine there is the old drawing TILE MAP thats commented out currently, "ed" is the sector main layer screen position is currently inside. That array system wasted to much ram, a map could be 80+MB big, current save file system was 170kb for a handfull of tiles.


some code printed out here quickly:


old render system:



Code:
while(d<5){while(c<selt[ed][d]){

  eX=(tile[ed][d][c][0]-screen_layer[d][0])*pixel_to_gl_X;

  eY=(tile[ed][d][c][1]-screen_layer[d][1])*pixel_to_gl_Y;

  draw2(eX,eY,w[tile[ed][d][c][2]],h[tile[ed][d][c][2]],tile[ed][d][c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));

c+=1;}c=0;d+=1;}d=0;

while(d<5){while(c<selt[ed+1][d]){

  eX=(tile[ed+1][d][c][0]-screen_layer[d][0])*pixel_to_gl_X;

  eY=(tile[ed+1][d][c][1]-screen_layer[d][1])*pixel_to_gl_Y;

  draw2(eX,eY,w[tile[ed][d][c][2]],h[tile[ed][d][c][2]],tile[ed][d][c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));

c+=1;}c=0;d+=1;}d=0;

while(d<5){while(c<selt[ed+50][d]){

  eX=(tile[ed+50][d][c][0]-screen_layer[d][0])*pixel_to_gl_X;

  eY=(tile[ed+50][d][c][1]-screen_layer[d][1])*pixel_to_gl_Y;

  draw2(eX,eY,w[tile[ed][d][c][2]],h[tile[ed][d][c][2]],tile[ed][d][c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));

c+=1;}c=0;d+=1;}d=0;

while(d<5){while(c<selt[ed+51][d]){

  eX=(tile[ed+51][d][c][0]-screen_layer[d][0])*pixel_to_gl_X;

  eY=(tile[ed+51][d][c][1]-screen_layer[d][1])*pixel_to_gl_Y;

  draw2(eX,eY,w[tile[ed][d][c][2]],h[tile[ed][d][c][2]],tile[ed][d][c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));

c+=1;}c=0;d+=1;}d=0;



New render system wich goes through all tiles in the map file several times, one for each layer.





Code:
while(d<5){while(c<selt2){

  if(tile[c][4]==d){

   if(tile[c][3]>=ed-1&&tile[c][3]<=ed+1){

    eX=(tile[c][0]-screen_layer[3][0])*pixel_to_gl_X;eY=(tile[c][1]-screen_layer[3][1])*pixel_to_gl_Y;

    draw2(eX,eY,w[tile[c][2]],h[tile[c][2]],tile[c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));}

   if(tile[c][3]>=ed-51&&tile[c][3]<=ed-49){

    eX=(tile[c][0]-screen_layer[3][0])*pixel_to_gl_X;eY=(tile[c][1]-screen_layer[3][1])*pixel_to_gl_Y;

    draw2(eX,eY,w[tile[c][2]],h[tile[c][2]],tile[c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));}

   if(tile[c][3]>=ed+49&&tile[c][3]<=ed+51){

    eX=(tile[c][0]-screen_layer[3][0])*pixel_to_gl_X;eY=(tile[c][1]-screen_layer[3][1])*pixel_to_gl_Y;

    draw2(eX,eY,w[tile[c][2]],h[tile[c][2]],tile[c][2],1.0,0.0,colr,colg,colb,cola,-1-c-(d*1000));}

  }

c+=1;}c=0;d+=1;}d=0;



The current save system:





Code:
//:::::::::::::::::::::::::: SAVE.

if(saveh==1&&savehp==0){

  myfile.open ("map3.txt");

  myfile<<  selt2  <<endl;

  while(c<5){

  myfile<<  selt[c]  <<endl;

  c+=1;}c=0;

  while(c<9999){

  myfile<<  noldx[c]  <<endl;

  myfile<<  noldy[c]  <<endl;

  myfile<<  noldv[c][0]  <<endl;

  myfile<<  noldv[c][1]  <<endl;

  myfile<<  noldv[c][2]  <<endl;

  c+=1;}c=0;

  while(c<selt2){

  myfile<<  tile[c][0]  <<endl;

  myfile<<  tile[c][1]  <<endl;

  myfile<<  tile[c][2]  <<endl;

  myfile<<  tile[c][3]  <<endl;

  myfile<<  tile[c][4]  <<endl;

  c+=1;}c=0;

  myfile.close();

cout<<"SAVED..."<<endl;savehp=1;}saveh=0;


selt2 is the amount of tiles in total, selt[x] is the amount of tiles in each layer only.

shoot2.zip
 

Attachments

  • shoot2.zip
    5 MB · Views: 98
The screen can be inbetween sectors, if I only render one sector a lot of graphics will pop in and out, and if I dont render one screen in excess on all sides then graphics can end up overlapping sectors and then disapear all of a sudden when the edge of it should still be seen.


I dont know anything about vectors, is there any difference from arrays?
 
Back
Top