New to plugin design. Runtime freezing.

This forum is currently in read-only mode.
From the Asset Store
Fly Bound
$2.49 USD
Design for game, asset for game, game kit, UI design, completed design for game FLY BOUND
  • Tonight I was porting the Perlin Noise library I'm using for console applications to Construct...and everything went great, except that the library clamps a specific value between -1 and 1, and that value is somehow getting up to 600. It does look like the noise is being generated persistently, like it should be, but the amplitude is way off. Also at some point when I was trying to fix this, it randomly started freezing at runtime.

    I know the exact line it freezes at though.

    At the moment I'm just hijacking "MyExpression".

    long ExtObject::eMyExpression(LPVAL params, ExpReturn& ret)
    {
    	// Get the example parameter
    	float XPos = params[0].GetFloat();
    	float YPos = params[1].GetFloat();
    	float XDim = params[2].GetFloat();
    	float YDim = params[3].GetFloat();
    
    	float CheckX = XPos/XDim;
    	float CheckY = YPos/YDim;
    
    	Perlin *PerlinMap = new Perlin(perlinOctaves,perlinFrequency,perlinAmplitude,perlinSeed);
    
    	float ValueAt = PerlinMap->Get(CheckX, CheckY);
    
                delete PerlinMap;
    
    	// Return 0 using ExpReturn's operator=
    	// Use ret.ReturnString() for strings.
    	return ret = ValueAt;
    }
    [/code:2igtm02p]
    
    It's the PerlinMap->Get line that kills the runtime process, and I have no idea why. I've used it before and it works great. If anything killed Construct I'd assume it'd be throwing a Perlin Noise Map on the heap...I *strongly* suspect that I'm creating this object dynamically when I should be letting Construct know about it ahead of time in the Serialization or something, but that doesn't seem to be a problem. The thing was (kind of) functioning for a while before I did something to it, and even then, it's buggier than it has been in prior programs - with no modifications to the code, so I'm thinking I'm invoking ACE incorrectly or something. Here's that ACE entry:
    
    [code:2igtm02p]	/////////////////////////////
    	// Expressions
    	// ADDEXP(List name, Category, Display string, Function address, Flags)
    	ADDPARAM(PARAM_VALUE, "X", "Your position along the X Plane, in percentile.");
    	ADDPARAM(PARAM_
    	ADDPARAM(PARAM_VALUE, "Y", "Your position along the Y Plane, in percentile.");
    	ADDPARAM(PARAM_VALUE, "XD", "X Dimension");
    	ADDPARAM(PARAM_VALUE, "YD", "YDimension.");
    	ADDEXP("My expression", "My category", "MyExpression", &ExtObject::eMyExpression, RETURN_FLOAT);[/code:2igtm02p]
    
    Right now, all I'm using is the code within the object itself, one expression to get the noise value at a specific coordinate, and four variables, accessible both at edit time and runtime, and I followed the tutorial with the Color Gradients.
    
    I'm not even sure how to hook VC++'s debugger into Construct properly to debug this. Do any of you guys have any tips? I know you probably know nothing of the Perlin class I'm using, I'm just asking for how to get started debugging. Originally this was a console program and I could carefully watch what was going on using my IDE's debugger, and since this DLL is intermediary between the executable, the debugger isn't working, or I haven't properly set it up. Also any common sense debugging tips would be appreciated.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • i dont know if this is a mistake copypasting but you have an ADDPARAM(PARAM_ after your first param...since these are macros and not functions, it might still be compiling, but not ina any sensicalw way..as for debugging. run a exe preview, and goto vs and debugging attach to process, and attach it to the temp.exe....you have to choose the debugging exe when building for it to work

  • Why allocate a new Perlin then delete it in one function? It's slower, and you risk leaking memory if Get() threw an exception, you may as well just have it as a local.

    To debug a plugin, make sure you've built a debug runtime version of your plugin and that it's in the IDE's runtime plugins folder. Then, locate the Temp.exe that the IDE creates for previews, which should be somewhere under your Users Appdata folder (eg. C:\Users\<username>\AppData\Local\Scirra or something like that - AppData is a hidden folder so you need to make sure Windows doesn't hide hidden folders). In Visual Studio's project settings, set the debugger target to be that Temp.exe file, then click Start Debug. It should launch Temp.exe and start debugging your plugin.

    Note Temp.exe is replaced every time you preview, so make sure if you change the .cap you hit preview, close it, then start the debug. Also, if you change your code you need to rebuild your plugin and put it back in the plugins directory, otherwise you'll get a "symbols don't match" error.

  • Ashley you're a life saver! The object was NOT the issue, but your debug information pointed me to the fact that none of the parameters for the noise had been initiated, which pointed me to the fact that I was not loading my runtime serialization stuff in the same way I packed it up at edittime.

    I packed it up as ar >> 1 >> 2 >> 3 >> 4;

    I was reading it as:

    ar >> 1;

    ar>>2;

    ar >> 3;

    ar >> 4;

    <img src="http://content.screencast.com/users/Arsonide/folders/Jing/media/f221854e-eef3-4938-8e49-2097990709f3/Terrain.png">

    The fruit of my labors! Keep in mind that the noise is much smoother than that, but I just whipped up a quick test program using 64x48 sprites. Over 3000 of them. I'm going to keep working on this and release it to the community to solve everyone's random terrain problems.

  • really cool arsonide

    I will be using this

    thanks

  • That looks great! I too would love to get my hands on it.

  • Right now I'm trying to whip up a test program and having issues with such a large tilemap and performance. I suppose that's more of a problem of the way the tilemap is set up and not the Perlin Noise object though.

    So basically how it works is this, there are three settings that affect the detail of the map - Octaves and Frequency affect the quality, Amplitude affects the height ( -Amplitude to +Amplitude is the values that it gives out. ), and lastly, the seed. Basically, if you give it the same seed, it will give you the same noise...so the terrain isn't only random - it's persistent. So it can be used in an RPG or whatever and integrated into the save game, and there is no limit to how much terrain you can come up with, if you keep adjusting the seed.

    The noise itself does not have a width and a height, but is percentage based. In other words, it doesn't think in terms of "X,Y", but more like "52% across the area, 32% down the area). I will set it up so that it uses layout coordinates, for simplicity, but the side effect of this is that, since it doesn't compute stuff in finite amounts, you can have a layout as large as you want, and the noise will still look good.

    The "Water Level" you see in that screenshot, was just an arbitrary number chosen by me. Basically those are all one white sprite in an array paste. At layout start it runs all of them against the PerlinNoise object and colorizes them according to the amplitude that is output where they are at. I do a system comparison event on that, if it's under zero it's water, and above zero is land. The entire cap is two objects, six conditions, and four actions...and if I change the seed a completely different output is given, as expected.

    I thought about making this into a "terrain" plugin, and integrating a lot of functionality specific to terrain, but perlin noise has applications unrelated to terrain, so I thought I'd keep it simple and let the cap designer use it how he wants to use it. I've wanted something like this in Construct *forever*. If and when someone else comes up with a Tilemap object - combined with this, we're talking the end of comparisons to MMS and Game Maker, because Construct will simply be a superior program.

  • I figured there would be some issues with rendering, that's a lot of sprites to generate. Have you thought about just having it output to some kind of array? That would allow the user to use different objects, like canvas, or even minimap. Plus you wouldn't have to render it all at one time, and you could use several small tiles instead of one big one. Of course tile-ability would come into play with that.

  • That's the beauty of it's simplicity. The Perlin Noise object doesn't store anything. You can put the noise into an array or a canvas if you want to by looping through the array indexes or the pixels on a canvas. All the noise object will do is tell you what the amplitude is in a given area on it - since it uses a seed to figure that out, it doesn't even actually "store" the noise itself in any way. That's what I meant when I said it can be as detailed as you want it to be. If you want 1 to 1 pixel canvas art Perlin Noise, it can do that. If you want tilemaps, it can also do that.

    It's a computational tool, it has no visual component unless you give it one. In the editor it doesn't even show up, it's OF_NODRAW like the Keyboard and Mouse plugin.

  • Sounds good, you could do several different things, like use just one sprite, then paste it into a canvas.

    Probably a ton of interesting things you can do with fx as well.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)