Ruskul's Forum Posts

  • Sorry for the lack of clarity.

    I am working on behaviors, so this is all runtime side. It would be in instance.js. Now that you ask that, I am curious, I should probably be setting up that reference to at a different point? I've read the manual, but I'm still pretty shaky when it comes to the architecture the general flow that happens when objects are created, when the code gets accessed, etc...

    For my purposes, it is to set up cross communication between behaviors and other behaviors, or other plugins.

    This way I can use behaviors to create modular behaviors, with a "handler" behavior that ties them all together. Then, all I have to do in the editor is attach whatever behavior modules I want, attach the handler, and it all gets interfaced through the handler in event ACEs.

  • IIRC maybe the C2 runtime did that, but the C3 runtime doesn't, so this hasn't been the case for years. JavaScript and modern GCs are so good that kind of pooling approach doesn't matter any more.

    Respectfully and in humor, lol.... What?!

    No way! For games that it matters for, it does matter alot. For the rest, it doesn't hurt any. A generic pool usually always helps performance for any objects being created/destroyed at runtime. Tweaking, or supplying specifics can improve a pool even further.

    Allocating and releasing memory takes cpu work, no question. Better gc doesn't really change that, just lessens the impact... but it doesn't eliminate the impact. Call me a skeptic - but industry standard is still to pool - and that is regardless of whether you are in c++, c#, js, or heaven forbid gsl. If you pool in unity or unreal, I can't see a reason why you wouldn't in js in construct, given c#/c++ has better performance at runtime.

    You can easily test this with an objectpool made out of construct events using inefficient arrays and pick by uid, and it will perform better than simply creating and destroying objects, despite the pool having a large overhead for looping objects. I still get 20% better performance in this case. If you perform the same equivalent loops to the non-pooling method, the performance increases. Move the pool to scripts and you will see bigger benefits. I didn't do it in script form because I still have to lumber through js and the api, but I'm sure you could whip something out to test in minutes.

    For a bullet hell game or any other where objects are frequently being destroyed and created, object pools are a absolute must for smooth performance.

    If I run equivalent loops for pooled/vs non pooled objects to eliminate event overhead for loops, I can get 5x the fps for pooled objects in perfect contexts. Engine side, you should be able to do even better by properly moving those objects to a space where nothing updates for them and they aren't "technically" on the layout anymore.

  • Hey all,

    So I've been having issues with some calls.

    For example, I see GetSdkInstance(); under behavior instance, in the manual, but when I call the function,

    this.GetSdkInstance();

    it doesn't work

    I have to do:

    this._inst.GetSdkInstance();

    I know _inst is supposed to be private, but I get an error when I do:

    this.GetInstance().GetSdkInstance();

    In both cases the error listed in the console is that there are no functions found.

    It must be said, I am a complete moron with js coming from c++ and c#, so this might be a simple noob mistake. is it supposed to be "self.whatever..." instead of this?

    Also, when making a call during the constructor, I get null for some of those. I expect that is because the order of initialization isn't guaranteed? But is there a place to call such things during creation that would be good for creating dependencies?

    Thanks a bunch!

  • One final caveat, if you are setting frames only to get collision polygons for a behavior to use, this works really well, however - I have a strict editor side hands off policy on the changing animations or frames for objects using this behavior.

    This results in a behavior that can only be used so long as the user adheres to "rules" of use. This is true of any code, but its not a grand replacement for a proper collision system with a dedicated api for all the obvious reasons.

    Such a dedicated api would allow for the creation of custom platformers and 8way controllers. The built in ones are nice, but they have issues you can't resolve via events. Mario and sonic behaviors clones with exacting detail could totally be created and shared. But not currently, not without hacks like this, meaning its likely to break in the future when Scirra changes things.

  • Hey all,

    I have some events I want to only run on the start of the first layout started, but for ease of debugging, I don't want them tied to a particular layout.

    I've created a data object with boolean "IsInitialized". At start of layout, I check this boolean. If false, I run the startup routine.

    It works, but I was curious if there was a better way.

  • Ah, yes... Spot on Ashley ! I found the forum post I was thinking of from 2013.

  • I thought construct ran an internal pool of objects in order to recycle objects destroyed objects and improve/reduce overhead for object creation/destruction in game.

    I didn't know if we are supposed to hook into that in order to avoid re-initializing certain types of data, or how data is handled through constructs instance creation, destruction, sent to pool, returned from pool, and absolute destruction.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey all!

    I have a behavior I made to solve a really simple problem. It tracks the state(s) of a binary toggle, flip, switch, or whatever you want to call it with extra benefits!

    The behavior automatically tracks last state, the time at which a state change occurs, the current state, and has conditions for entering/exiting (similar to input On key pressed, or On key Released).

    In addition, you can use it to track previous entry/exit times for states.

    The behavior uses an array of states, and accesses them by ID, but only updates the number you specify, keeping it lean and simple. The Id system allows you to determine what each state is. For example Forward = 0, Right = 1, Back = 3, and so on. States are also stored as numbers, so technically, you can have a state existing in a series of substates.

    I use it for character input (player or ai), and for tracking simple states, such as IsOnGround. In this case, I would have a variable on a data object called IsOnGround and set it to be the desired ID, then use it like so:

    Is entity overlapping water? -> Entity Set State(IsOnGround) to 1

    later on in the project:

    //True during the first frame a state is switched on from off

    entity enters state (IsOnGround) -> Do things

    //True during the first frame a state is switched off from on

    entity exits state (IsOnGround) -> Do Things

    You can combine them in nice ways like this (in this case to forgive/allow a player to jump when they pressed the input a fraction of a second too early):

    entity state (jump) was entered <= 0.1 seconds ago

    entity enters state (IsOnGround)

    ---> //call the jump behavior

    Would anyone else like access to this? I was hoping for feedback on naming conventions and ease of use, as well as use cases people find for it.

    ----

    Current ACES:

    Actions:

    //Given an id, sets a state to the value provided. Both are numbers

    -Set State(Id, State)

    //Called after all changes to states are made. This is used to compute new enter/exit times for any states that have changed. The time is calculated based on the instances dt

    -Confirm States

    //Set the total number of states to process (hard coded limit atm)

    -Set State Count

    //Resets all states and times to default/off state.

    -ResetAll

    -Reset(id)

    //Set the behavior to auto rollover input and advance the internal clock

    -Enable

    -Disable

    //Manually advance teh internal clock and roll over states from current to last

    -Advance frame (dt)

    Expressions:

    Returns the current value for a state, given the id

    -State(id)

    //Same as above, but for the last frame

    -LastState(id)

    //Returns 1 if the state at id was switched on during this frame

    -Enter(id)

    //Returns 1 if the state at id was switched off this frame

    -Exit(id)

    //Returns the time for a state entering or exiting or the previous one.

    -EnterTime(id)

    -ExitTime(id)

    -LastEnterTime(id)

    -LastExitTime(id)

    //Returns the number of states being processed

    -Count

    //Returns the Objects current time in seconds

    -Clock

    Conditions:

    //Returns true if state(id) is true,

    -State (id)

    -Last State (id)

    -Enters (id)

    -Exits (id)

    -Compare exit time (id)

    -Compare Last exit time (id)

    -Compare enter time (id)

    -Compare Last Enter Time (id)

    -Compare Clock

    -IsEnabled

  • Ashley , Uh, just a quick clarification - was there a place to add a function to be called when an object gets added to the pool or removed?

    I don't know if it matters, but currently I stuff any variables/objects I need on a behavior instance via the constructor by means of:

    this._whateverIneed = {
    	thing : true,
    	somenum : 42,
    	etc : "..."
    } 
    

    But I wasn't sure if I needed to clean up in any specific way afterwards - or if I needed to do anything between an object being in use / out of use.

    Thanks for answering so many of my questions today!

  • Applying editor-side changes while the editor is open is an extremely difficult problem. What happens to the project you are looking at if the addon has a breaking change made while you have a project open? There are probably hundreds of ways the editor could crash after that, and it's infeasible to spend weeks or months doing all the work to sort out all those possible cases instead of doing other things like new feature development, just so you don't need to reload the editor during development.

    That doesn't apply to the runtime though, so you can in general make any runtime change and it will apply on the next preview.

    I wasn't meaning to say the ability to make hot changes to the editor should be added! I totally agree, not worth the dev time. To be fair too, in unity you basically have no choice, all game logic is scripts that must be compiled after every change, whether runtime or editor side.

  • Well, I can't say I didn't do anything to break it, but I also didn't make any changes (that I was aware of) in order to break it. I didn't make anychanges to fix it and after restarting everything it was all good. I am curious if my server went down at just the right moment, could an expression fail to be loaded?

    In another instance I was breaking it on purpose, ASHLEY. But I was kinda expecting to be able to still open the project and remove all offending lines. I like to build up a project with all the ACES that a behavior adds, but as I work, sometimes I decide a behavior shouldn't have a particular ACE and I remove it... breaking the whole project.

    It would be super cool to be able to go into a project with errors and fix them.

    But yeah, the issue in that case is all on me, lesson learned. Delete All aces in project first before deleting in behavior.

  • If you're using a local server for addon development, and you end up in a mess, the easiest way out is to clear browser storage (which has the effect of uninstalling all addons).

    That is gold, thank you!

  • Cool, Thanks!

  • Shoots, thanks - good to know.

    As far as GC goes though, for example, I thought you said vector2 were dangerous because of gc. I try not to optimize ahead of time, but just wanted to make sure I was following best practices in this case.

  • It depends what your comparing it to. You don't need unreal engine, but if your going to add 3d then at least add collisions and 3d ray casting to finish the feature set. One of my biggest gripes with C3 is that a lot of things get added but never completed. Its just enough to entice you with what could be possible, but ultimately leaves you frustrated with its limitations.

    To be fair, I think the 3d in c3 isn't meant to be true 3d. Its all smoke and mirrors on what are essentially 2d games.

    I would agree with that what you say in a way, and I think that is my point. We still don't have a proper set of tools for 2d collisions and rays or a way to traverse object hierarchies. Adding in anything for 3d before even finishing this in 2d seems backwards.

    Consider that currently there are no collision resolution functions except PushFromSolid (requiring a behavior to use, and solid tag on objects). This is very restrictive given the way c3 families and behaviors work. Raycasting is similar. Box2d provides an impressive array of tools, but most are not available when using that behavior (requiring additionally using c3 overlaps).

    In my mind, given physics engine code is opensource, accessible, and to be found in great variety, I think c3 could easily offer more than it does in this realm, natively. Collisions are really core functionality (as are vectors), and c3 might be the only game engine I have used that won't provide the latter, and has a very simple simple solution for the former.

    This is all okay if you are making retro style platformers (even then there are some missing tools for that), because the functions are lightweight and can be handled in events.... but, 3d?

    Currently in 2d, we have no way of defining collision objects except by adding in objects with all sorts of extras we don't need. We have no way of creating compound colliders except by means of creating multiple sports or iterating through a sprites animation frames (bad for performance just to get a polygon). This is going to be compounded in 3d. We have no way of testing overlaping shapes and returning the points of contact etc... Box2d comes with a full sweet of tools, but many are not officially exposed. C3 doesn't have a model for detecting continuous collisions. C3 doesn't have swept shapes (which can be built off continous collision solvers). This list of issues is largely only solvable by rolling out your own code, but then you have the unpleasant issue with the fact you can't extend the editor.

    All this applies to 3d. You need everything I just listed, or you are going to have the most basic problems of getting a fully 3d character controller up and running. You need to know surface angles at point of collision, and so on.