egofree
|
|
Posted on: June 21, 2013, 07:36:39 am |
|
|
Joined: Jun 2013
Posts: 601
|
I'm a developing a platform game with a big room. When the game starts, the view is located according to the player position. In the beginning, the player position is in the middle of the room. Everything is fine. But then I created an object obj_game_controller in order to deactivate objects outside the view. I added this object in the top-left corner of the room.
In the step event of obj_game_controller, i've the following code :
instance_deactivate_region(view_xview[0], view_yview[0], view_wview[0], view_hview[0], false, true); instance_activate_region(view_xview[0], view_yview[0], view_wview[0], view_hview[0], true The problem now is that the view now is always located to the top left corner of the room. The view_xview[0] and view_yview[0] return zero. I tried my code with GM 8.1 and i don't have this problem. In GM view_xview[0] and view_yview[0] return the correct values according to the player position. Does anybody know what is the problem ?
|
|
« Last Edit: June 21, 2013, 07:40:51 am by egofree »
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #1 Posted on: June 21, 2013, 07:51:49 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
How big is your game? I might ask you to attach [snip]ENIGMAsystem/SHELL/Preprocessor_Environment_Editable/IDE_EDIT_objectdeclarations.h[/snip]. Also, maybe [snip]ENIGMAsystem/SHELL/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h[/snip]. I fear it might have declared those two variables locally, or is using them locally.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
egofree
|
|
Reply #2 Posted on: June 22, 2013, 03:31:31 am |
|
|
Joined: Jun 2013
Posts: 601
|
How big is your game?
Are you talking about the room size ? The room width is 3200 and the height is 1136. I am using only objects (16x16 pixels), not tiles. There is thousands of objects, and i don't know exactly how much. I might ask you to attach ENIGMAsystem/SHELL/Preprocessor_Environment_Editable/IDE_EDIT_objectdeclarations.h. Also, maybe ENIGMAsystem/SHELL/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h. I fear it might have declared those two variables locally, or is using them locally.
I don't understand, what do you mean by attaching these files ? Modifying an 'include' file or something similar ? By the way i did some more tests, and i tried instead : instance_deactivate_all(true); instance_activate_region(view_xview[0], view_yview[0], view_wview[0], view_hview[0], true); I've the same problem, but with 'instance_deactivate_all' there is also a huge memory leak, as the memory use of the game is exploding and after a moment the java runtime crashs. I am sure also that it's the deactivate function which resets the view and not the activate.
|
|
« Last Edit: June 22, 2013, 03:36:27 am by egofree »
|
Logged
|
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #5 Posted on: June 22, 2013, 10:40:43 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Nowhere in that entire file does the word "view" appear. It's probably for the wrong game; could you build your game in ENIGMA, then re-upload those files?
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #7 Posted on: June 22, 2013, 03:02:01 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
The view is always at (0,0) because you deactivate the player before the view can follow him. You can fix it by either creating the player object after deactivating instances, or calling [snip]instance_activate_object(obj_blagger)[/snip].
You're going to run into other problems, though, from sprites not animating while their owning objects are deactivated. You could fix that by having the controller object keep track of a frame count for all instances, if that's your only other issue.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
egofree
|
|
Reply #8 Posted on: June 23, 2013, 02:46:00 am |
|
|
Joined: Jun 2013
Posts: 601
|
The view is always at (0,0) because you deactivate the player before the view can follow him.
Thanks for your help Josh. What i don't understand is that the player should never be deactivated in the first place. In fact i am using the following code : instance_deactivate_region(view_xview[0], view_yview[0], view_wview[0], view_hview[0], false, true); Here is the definition of the instance_deactivate_region : instance_deactivate_region(left,top,width,height, inside,notme) I've set the value of inside to false, this means that everything outside the region should be deactivated.
|
|
|
Logged
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #10 Posted on: June 23, 2013, 05:46:58 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
While that code is 150% fatter than it needs to be, it is correct.
The player gets deactivated because the view does not instantly move to encompass the player. When your code starts, there is no player, and the view is still at (0,0). You then create a player, because one does not exist, but you create him outside of the view. You then deactivate everything outside the view, which hasn't moved.
That's why creating the player after calling your deactivation code will fix it.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
polygone
|
|
Reply #11 Posted on: June 23, 2013, 07:44:35 am |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
I've searched in the source code of ENIGMA the function and i found in coll_funcs.cpp the following code :
if (inside) { inst->deactivate(); enigma::instance_deactivated_list.insert(inode_pair((*it)->id,it.it)); } } else { if (!inside) { inst->deactivate(); enigma::instance_deactivated_list.insert(inode_pair((*it)->id,it.it)); }
I am not an expert in C++ but it seems to me that the code is the same, whatever the value of inside. Am i right ?
That's not the full code, this is: if (left <= (rleft+rwidth) && rleft <= right && top <= (rtop+rheight) && rtop <= bottom) { if (inside) { inst->deactivate(); enigma::instance_deactivated_list.insert(inode_pair((*it)->id,it.it)); } } else { if (!inside) { inst->deactivate(); enigma::instance_deactivated_list.insert(inode_pair((*it)->id,it.it)); } } ie it requires: if (((left <= (rleft+rwidth) && rleft <= right && top <= (rtop+rheight) && rtop <= bottom) && inside) || (!(left <= (rleft+rwidth) && rleft <= right && top <= (rtop+rheight) && rtop <= bottom) && !inside)) But yes that could be simplified to: if ((left <= (rleft+rwidth) && rleft <= right && top <= (rtop+rheight) && rtop <= bottom) == inside) EDIT: and I've just seen that Josh has already committed that, though he didn't think to look through the rest of the file for the same thing.
|
|
« Last Edit: June 23, 2013, 09:00:51 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
Josh @ Dreamland
|
|
Reply #12 Posted on: June 23, 2013, 08:11:47 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Josh committed that long before you made your post. And those are the only _region based functions; I searched neighboring functions and found no similar constructs. Not to imply there wouldn't be any had I read through all the code, but I fix things on an as-notified basis.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
polygone
|
|
Reply #13 Posted on: June 23, 2013, 08:27:11 pm |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
In the circle functions:
if (intersects) { if (inside) { inst->deactivate(); enigma::instance_deactivated_list.insert(inode_pair((*it)->id,it.it)); } } else { if (!inside) { inst->deactivate(); enigma::instance_deactivated_list.insert(inode_pair((*it)->id,it.it)); } }
|
|
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
Josh @ Dreamland
|
|
Reply #14 Posted on: June 23, 2013, 09:40:27 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
{{sofixit}}
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|