Windows Minimap freezing the game

Discussion in 'Programming' started by pangrodzki, Sep 3, 2019.

Thread Status:
Not open for further replies.
  1. pangrodzki

    pangrodzki Member

    Joined:
    Mar 22, 2019
    Posts:
    4
    Event Draw GUI, o_MiniMap
    Room 5000x5000, 30 objects in GM

    Code:
    if background_index=background0 or background_index=2{
    draw_set_color(c_white)
    
    draw_set_alpha(0.90)
    draw_rectangle(xp,yp,xp+width,yp+height,false)
    draw_set_alpha(0.80)
    
    draw_set_color(c_white)}else{
    draw_set_color(c_black)
    
    draw_set_alpha(0.90)
    draw_rectangle(xp,yp,xp+width,yp+height,false)
    draw_set_alpha(0.80)
    
    draw_set_color(c_black)
    
    }
    
    
    
    xp= 1150
    yp= 450
    
    
    draw_set_color(c_blue)
    var enemyCount;
    enemyCount=instance_number(object2)
    for (k=0; k<enemyCount;k=k+1){
    enemyId=instance_find(object2, k)
    var wherex= xp + enemyId.x*(xscale)
    var wherey= yp + enemyId.y*(yscale)
    draw_circle(wherex,wherey,4,true)
    }
    
    draw_set_color(c_red)
    var enemyCount2;
    enemyCount2=instance_number(object3)
    for (k=0; k<enemyCount2;k=k+1){
    enemy2Id=instance_find(object3, k)
    var wherex2= xp + enemy2Id.x*(xscale)
    var wherey2= yp + enemy2Id.y*(yscale)
    draw_circle(wherex2,wherey2,4,true)
    }
    
    draw_set_color(c_yellow)
    var diament;
    diament=instance_number(object7)
    for (k=0; k<diament;k=k+1){
    diamentId=instance_find(object7, k)
    var wherex3= xp + diamentId.x*(xscale)
    var wherey3= yp + diamentId.y*(yscale)
    draw_circle(wherex3,wherey3,4,false)
    }
    
    draw_set_color(c_yellow)
    var punkty;
    punkty=instance_number(object10)
    for (k=0; k<punkty;k=k+1){
    punktyId=instance_find(object10, k)
    var wherex4= xp + punktyId.x*(xscale)
    var wherey4= yp + punktyId.y*(yscale)
    draw_circle(wherex4,wherey4,4,false)
    }
    
    
    
    
    draw_set_color(c_white)
    var budynek;
    budynek=instance_number(oBudynek)
    for (k=0; k<budynek;k=k+1){
    budynekId=instance_find(oBudynek, k)
    
    //if global.wybraniec.gracz=1{with(o_MiniMap){draw_set_color(c_red)}}else if global.wybraniec.gracz=2{with(o_MiniMap){draw_set_color(c_blue)}}
    //with (budynekId){
    //if gracz=1{}else if gracz=2{}
    //}
    var wherex5= xp + budynekId.x*(xscale)
    var wherey5= yp + budynekId.y*(yscale)
    draw_circle(wherex5,wherey5,4,false)
    }
    
    draw_set_color(c_orange)
    var twierdza;
    twierdza=instance_number(object12)
    for (k=0; k<twierdza;k=k+1){
    twierdzaId=instance_find(object12, k)
    var wherex6= xp + twierdzaId.x*(xscale)
    var wherey6= yp + twierdzaId.y*(yscale)
    draw_circle(wherex6,wherey6,4,false)
    }
    
    if global.gracz_tura=1{
    
    if view_object[0]=object3{
    draw_set_color(c_red)
    var kursor;
    kursor=instance_number(object3)
    for (k=0; k<kursor;k=k+1){
    kursorId=instance_find(object3, k)
    var wherex7= xp + kursorId.x*(xscale)
    var wherey7= yp + kursorId.y*(yscale)
    draw_circle(wherex7,wherey7,4,true)
    }
    }else{
    draw_set_color(c_red)
    
    var gracz;
    gracz=instance_number(object5)
    for (k=0; k<gracz;k=k+1){
    graczId=instance_find(object5, k)
    var wherex8= xp + graczId.x*(xscale)
    var wherey8= yp + graczId.y*(yscale)
    draw_circle(wherex8,wherey8,50,true)
    }
    }}
    
    else if global.gracz_tura=2{
    
    if view_object[0]=object2{
    draw_set_color(c_blue)
    var kursor2;
    kursor2=instance_number(object2)
    for (k=0; k<kursor2;k=k+1){
    kursor2Id=instance_find(object2, k)
    var wherex9= xp + kursor2Id.x*(xscale)
    var wherey9= yp + kursor2Id.y*(yscale)
    draw_circle(wherex9,wherey9,4,true)
    }
    }else{
    draw_set_color(c_blue)
    
    var gracz2;
    gracz2=instance_number(object5)
    for (k=0; k<gracz2;k=k+1){
    gracz2Id=instance_find(object5, k)
    var wherex10= xp + gracz2Id.x*(xscale)
    var wherey10= yp + gracz2Id.y*(yscale)
    draw_circle(wherex10,wherey10,50,true)
    }
    }}
    
    if background_index=background1{
    
    draw_set_color(c_dkgray)
    var mur;
    mur=instance_number(object0)
    for (k=0; k<mur;k=k+1){
    murId=instance_find(object0, k)
    var wherex11= xp + murId.x*(xscale)
    var wherey11= yp + murId.y*(yscale)
    draw_circle(wherex11,wherey11,4,false)
    }
    
    
    draw_set_color(c_dkgray)
    var mur2;
    mur2=instance_number(object15)
    for (k=0; k<mur2;k=k+1){
    mur2Id=instance_find(object15, k)
    var wherex12= xp + mur2Id.x*(xscale)
    var wherey12= yp + mur2Id.y*(yscale)
    draw_circle(wherex12,wherey12,4,false)
    }
    
    //draw_set_color(c_dkgray)
    var mur3;
    mur3=instance_number(object28)
    for (k=0; k<mur3;k=k+1){
    mur3Id=instance_find(object28, k)
    var wherex13= xp + mur3Id.x*(xscale)
    var wherey13= yp + mur3Id.y*(yscale)
    draw_circle(wherex13,wherey13,4,false)
    }
    
    //draw_set_color(c_dkgray)
    var mur4;
    mur4=instance_number(object26)
    for (k=0; k<mur4;k=k+1){
    mur4Id=instance_find(object26, k)
    var wherex14= xp + mur4Id.x*(xscale)
    var wherey14= yp + mur4Id.y*(yscale)
    draw_circle(wherex14,wherey14,4,false)
    }
    
    //draw_set_color(c_dkgray)
    var mur5;
    mur5=instance_number(object20)
    for (k=0; k<mur5;k=k+1){
    mur5Id=instance_find(object20, k)
    var wherex15= xp + mur5Id.x*(xscale)
    var wherey15= yp + mur5Id.y*(yscale)
    draw_circle(wherex15,wherey15,4,false)
    }
    
    //draw_set_color(c_dkgray)
    var mur6;
    mur6=instance_number(object19)
    for (k=0; k<mur6;k=k+1){
    mur6Id=instance_find(object19, k)
    var wherex16= xp + mur6Id.x*(xscale)
    var wherey16= yp + mur6Id.y*(yscale)
    draw_circle(wherex16,wherey16,4,false)
    }
    
    }else{
    
    draw_set_color(c_black)
    var mur;
    mur=instance_number(object0)
    for (k=0; k<mur;k=k+1){
    murId=instance_find(object0, k)
    var wherex17= xp + murId.x*(xscale)
    var wherey17= yp + murId.y*(yscale)
    draw_circle(wherex17,wherey17,4,false)
    }
    
    
    draw_set_color(c_black)
    var mur7;
    mur7=instance_number(object15)
    for (k=0; k<mur7;k=k+1){
    mur7Id=instance_find(object15, k)
    var wherex18= xp + mur7Id.x*(xscale)
    var wherey18= yp + mur7Id.y*(yscale)
    draw_circle(wherex18,wherey18,4,false)
    }
    
    //draw_set_color(c_black)
    var mur8;
    mur8=instance_number(object28)
    for (k=0; k<mur8;k=k+1){
    mur8Id=instance_find(object28, k)
    var wherex19= xp + mur8Id.x*(xscale)
    var wherey19= yp + mur8Id.y*(yscale)
    draw_circle(wherex19,wherey19,4,false)
    }
    
    //draw_set_color(c_black)
    var mur9;
    mur9=instance_number(object26)
    for (k=0; k<mur9;k=k+1){
    mur9Id=instance_find(object26, k)
    var wherex20= xp + mur9Id.x*(xscale)
    var wherey20= yp + mur9Id.y*(yscale)
    draw_circle(wherex20,wherey20,4,false)
    }
    
    //draw_set_color(c_black)
    var mur10;
    mur10=instance_number(object20)
    for (k=0; k<mur10;k=k+1){
    mur10Id=instance_find(object20, k)
    var wherex21= xp + mur10Id.x*(xscale)
    var wherey21= yp + mur10Id.y*(yscale)
    draw_circle(wherex21,wherey21,4,false)
    }
    
    //draw_set_color(c_black)
    var mur11;
    mur11=instance_number(object19)
    for (k=0; k<mur11;k=k+1){
    mur11Id=instance_find(object19, k)
    var wherex22= xp + mur11Id.x*(xscale)
    var wherey22= yp + mur11Id.y*(yscale)
    draw_circle(wherex22,wherey22,4,false)
    }
    
    }
    
    
    draw_set_color(c_blue)
    var baza;
    baza=instance_number(object13)
    for (k=0; k<baza;k=k+1){
    bazaId=instance_find(object13, k)
    var wherex23= xp + bazaId.x*(xscale)
    var wherey23= yp + bazaId.y*(yscale)
    draw_circle(wherex23,wherey23,8,false)
    }
    
    draw_set_color(c_red)
    var baza2;
    baza2=instance_number(object23)
    for (k=0; k<baza2;k=k+1){
    baza2Id=instance_find(object23, k)
    var wherex24= xp + baza2Id.x*(xscale)
    var wherey24= yp + baza2Id.y*(yscale)
    draw_circle(wherex24,wherey24,8,false)
    }
    
    draw_set_color(c_lime)
    var mur13;
    mur13=instance_number(object30)
    for (k=0; k<mur13;k=k+1){
    mur13Id=instance_find(object30, k)
    var wherex25= xp + mur13Id.x*(xscale)
    var wherey25= yp + mur13Id.y*(yscale)
    draw_circle(wherex25,wherey25,4,false)
    }
    
    draw_set_color(c_lime)
    var mur14;
    mur14=instance_number(object25)
    for (k=0; k<mur14;k=k+1){
    mur14Id=instance_find(object25, k)
    var wherex26= xp + mur14Id.x*(xscale)
    var wherey26= yp + mur14Id.y*(yscale)
    draw_circle(wherex26,wherey26,4,false)
    }
    Create
    Code:
    xp=0;
    yp=0;
    //height=300
    //width=300
    
    height=450
    width=450
    global.pokazuje=true
    xscale=width/room_width
    yscale=height/room_height
    
    
    I have some problems with fps - sometimes when I activate healthbars and names - it goes near 10. But when I deactivate code with "if" I can run game without obstacles on map. But I need theese obstacles... Because they have meaning in game.

    So what can I do with minimap? How to write this code? I like this type of minimap.What is the problem? Number of instances or my code in draw GUI event? Maybe both?
     

    Attached Files:

    Last edited: Sep 3, 2019
  2. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    664
    You are doing a lot of instance_find, instance_number, draw_* scripts in the draw event, and that, every frame.
    I would propose you use a surface and only draw what changed.

    For example:
    - have a gui object (oMinimap) or something like that.
    - In the create event, set a variable for the surface.
    - In the step event, check if the surface exists (create it if not)
    - In the draw event, check if the surface exists and draw it
    - In each object that you want to be drawn, add a "dirty" or "should_draw" variable
    - Everytime that instance is created, destroyed or changed/moved, set that variable to true
    - In the draw event, if the variable is true, target the minimap's surface and draw your circle

    This way, you will draw a lot less and make a lot less script calls. The performance should be much better.
    I can build you an example if you request me to.

    Hope this helps,
    Cedrik
     
  3. pangrodzki

    pangrodzki Member

    Joined:
    Mar 22, 2019
    Posts:
    4
    I am using Game Maker Studio 1.1

    Please make an example for me! I will be really happy.
     
  4. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    664
    I made an example in GMS 2, I'll convert it to GMS 1 tomorrow.
    I've changed the logic a bit since what I told you was a quick idea but now I have something even better.

    1. I made use of lists to store instances that need to be updated. The instance itself shoudn't draw itself on the minimap. Instead it should "ask" to be drawn. I made that using a script "updateInstanceOnMinimap()" which adds the instance to a list that will then be updated when the minimap is ready.

    2. The script adds additional information like the current position of the instance. This is used later when the minimap needs to "clear" only the instances that moved.

    3. Drawing is done via parents. This way no need to write 13 different loops to draw circles of different colors. It also forces instances to use "a set of variables", a contract basically, so the minimap doesn't have to guess anything about them! :D

    I'll publish it tomorrow, it's already late here.
     
  5. pangrodzki

    pangrodzki Member

    Joined:
    Mar 22, 2019
    Posts:
    4
    Where is it? Can you give link?
     
  6. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,859
    There is no such thing as GameMaker 1.1... What version are you using exactly? Lots of things have changed over the last few years between versions.
     
  7. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    664
    He probably meant 1.4 (I often make the 1.1 typo as well lol)
     
  8. pangrodzki

    pangrodzki Member

    Joined:
    Mar 22, 2019
    Posts:
    4
  9. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    664
    Hey sorry I was moving yesterday, I'll send it tonight, I have to re-download GM 1.4 and internet is slow until they come to change it :/
     
  10. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    664
    Please update your GameMaker then, 1.4 is the latest version, and if you have GameMaker Studio 1.x, you can freely get any updates for 1.x.
     
  11. CedSharp

    CedSharp Member

    Joined:
    Sep 5, 2016
    Posts:
    664
    Here is the example: Mega.nz download link

    It's a simple ball example.
    The minimap draws different type of "balls" (basically different color).
    When you click a ball, it changes position and gets "added" to the minimap "pending list".

    This way your minimap doesn't redraw all the time, only when it's pending list is not empty.
    I also made a basic parent-child relationship to show you that I only need to care about drawing
    the parent, no need to test each object that I need to draw :D

    I'm using queues because I can "add" and "remove" easily with them, feels better than
    iterating an array.

    Let me know if you need more assistance!
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice