• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Dear Yoyo...

slayer 64

Member
Stop changing things. I am still using Game maker studio 1.4.1763 and things are changing. Code used to work. Now it doesn't. I haven't touched it in years. something as low level as a div should not be breaking.

I am on the stable release because I don't want to fix your software. ds_grids have been pissing me off lately because of your internal changes.

I had to start working on this script when I troubled shooted that div was giving me trouble.

Code:
///heightmapCreate(cellsx,cellsy,cellsInChunkx,cellsInChunky,cellSize,defaultColor,defaultAlpha)
/*
    0 cellsx
    1 cellsy
    2 cellsInChunkx
    3 cellsInChunky
    4 cellSize
    5 defaultColor
    6 defaultAlpha
   
    returns a new heightmap.  
    cells is the number of squares the heightmap is made of. 
    cellSize is the size of each square. 
    cellsInChunk is how many squares will be in each chunk. if you want the heightmap to be one chunk, use a larger number than cells (99999). 
    the heightmap can be one big chunk or many smaller ones, 
    this is useful for fast rendering but also being able to reconstruct areas in real time, you can make chunks fairly big without lagging. 
    defaultColor being a gm color.
    defaultAlpha being 0-1
*/

var chunk,
    ax,ay,
    bx,by,
    cx,cy;

with instance_create(0,0,slayersUpgrade.slayersObject)
{
    cellSize=argument4
    defaultColor=argument5
    defaultAlpha=argument6*255

    vCells=vecCreatexyz(argument0,argument1,1)
    vPoints=vecCreatexyz(argument0+1,argument1+1,1)
    vCellsInChunk=vecCreatexyz(argument2,argument3,1)
    vSizePixels=vecCreatexyz(argument0*cellSize,argument1*cellSize,1)
    minz=0
   
    //this is for input error checking
    normalsHaveBeenSet=0
   
    //might need an expanded mesh of the heightmap
    mesh=noone
    gridMeshTriangles=-1
   
    vertex_format_begin()
    vertex_format_add_position_3d()
    vertex_format_add_normal()
    vertex_format_add_colour()
    vertex_format_add_textcoord()
    vertexFormat=vertex_format_end()
   
    //these are the basics of the heightmap the user can modify
    gridz=ds_grid_create(vecx(vPoints),vecy(vPoints))
    gridr=ds_grid_create(vecx(vPoints),vecy(vPoints))
    gridg=ds_grid_create(vecx(vPoints),vecy(vPoints))
    gridb=ds_grid_create(vecx(vPoints),vecy(vPoints))
    grida=ds_grid_create(vecx(vPoints),vecy(vPoints))
   
    ds_grid_clear(gridr,color_get_red(defaultColor))
    ds_grid_clear(gridg,color_get_green(defaultColor))
    ds_grid_clear(gridb,color_get_blue(defaultColor))
    ds_grid_clear(grida,defaultAlpha)
   
    //each cell in this grid is a refrence to a buffer so we can write to it
    gridSquares=ds_grid_create(vecx(vCells),vecy(vCells))
   
    //remeber chunks
    listChunks=ds_list_create()
   
    var tempw,temph,addOnTox,addOnToy;
   
    if vecx(vCells) mod vecx(vCellsInChunk)>0 addOnTox=1 else addOnTox=0
   
    if vecy(vCells) mod vecy(vCellsInChunk)>0 addOnToy=1 else addOnToy=0
   
    //FAILS
    //tempw=vecx(vCells) div vecx(vCellsInChunk)+addOnTox // = a stupidly large number
    //temph=vecy(vCells) div vecy(vCellsInChunk)+addOnToy // = a stupidly large number
   
    //STILL FAILS
    //tempw=(vecx(vCells) div vecx(vCellsInChunk))+addOnTox // = a stupidly large number
    //temph=(vecy(vCells) div vecy(vCellsInChunk))+addOnToy // = a stupidly large number
   
    //DEFINATLY WORKS
    tempw=floor(vecx(vCells)/vecx(vCellsInChunk))+addOnTox // = 3. good.
    temph=floor(vecy(vCells)/vecy(vCellsInChunk))+addOnToy // = 3. good.
   
    show_message("tempw "+string(tempw)+"#temph "+string(temph)+"#addOnTox "+string(addOnTox)+"#addOnToy "+string(addOnToy))
   
    gridChunks=ds_grid_create(tempw,temph)
        //vecx(vCells) div vecx(vCellsInChunk)+(vecx(vCells) mod vecx(vCellsInChunk)!=0),//original code written in 2014
        //vecy(vCells) div vecy(vCellsInChunk)+(vecy(vCells) mod vecy(vCellsInChunk)!=0))
    ds_grid_clear(gridChunks,noone)
   
    show_message("#chunk grid width "+string(ds_grid_width(gridChunks))+"#chunk grid height "+string(ds_grid_height(gridChunks))+
                 "#cells x "+string(vecx(vCells))+"#cells y "+string(vecy(vCells)))
   
    //create all the chunks we'll ever need
    for(ax=0 ax<vecx(vCells) ax+=1)
    for(ay=0 ay<vecy(vCells) ay+=1)
    {
        bx=ax div vecx(vCellsInChunk)
        by=ay div vecy(vCellsInChunk)
       
        chunk=ds_grid_get(gridChunks,bx,by)
       
        //this is where errors started because the gridChunks wasn't large enough.
        //chunk became undefined because it was outside of the grid.
        if is_undefined(chunk)
        {
            show_message(   "ax "+string(ax)+"#ay "+string(ay)+
                            "#bx "+string(bx)+"#by "+string(by)
                            )
        }
       
        if chunk=noone chunk=heightmapChunkCreatexy(id,bx,by)
       
        with chunk
        {
            bx=ax*other.cellSize
            by=ay*other.cellSize
           
            cx=bx+other.cellSize
            cy=by+other.cellSize
           
            ds_grid_set(other.gridSquares,ax,ay,
            buffer_vertex_add(buffer,bx,by,0,     0,0,1,     0,0,other.defaultColor,other.defaultAlpha))
           
            buffer_vertex_add(buffer,cx,by,0,     0,0,1,     1,0,other.defaultColor,other.defaultAlpha)
            buffer_vertex_add(buffer,cx,cy,0,     0,0,1,     1,1,other.defaultColor,other.defaultAlpha)
           
            buffer_vertex_add(buffer,cx,cy,0,     0,0,1,     1,1,other.defaultColor,other.defaultAlpha)
            buffer_vertex_add(buffer,bx,cy,0,     0,0,1,     0,1,other.defaultColor,other.defaultAlpha)
            buffer_vertex_add(buffer,bx,by,0,     0,0,1,     0,0,other.defaultColor,other.defaultAlpha)
        }
    }
   
    return id
}
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Could you provide a little more clarification on what changed/broke about div? I haven't used it too excessively in my projects and haven't noticed anything new.
 

slayer 64

Member
For some reason the first two cases would return a very large number. I don't know if an integer wrapped around or what. The values being passed into the formulas are all positive. I added parenthesis in the second case.
Code:
//FAILS
   //tempw=vecx(vCells) div vecx(vCellsInChunk)+addOnTox // = a stupidly large number
   //temph=vecy(vCells) div vecy(vCellsInChunk)+addOnToy // = a stupidly large number
   
   //STILL FAILS
   //tempw=(vecx(vCells) div vecx(vCellsInChunk))+addOnTox // = a stupidly large number
   //temph=(vecy(vCells) div vecy(vCellsInChunk))+addOnToy // = a stupidly large number
   
   //DEFINITELY WORKS
   tempw=floor(vecx(vCells)/vecx(vCellsInChunk))+addOnTox // = 3. good.
   temph=floor(vecy(vCells)/vecy(vCellsInChunk))+addOnToy // = 3. good.
 
Top