ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator General js questions
person icon
Dieter
Guest
Quote
2023-08-28 11:10:07

Thanks to all you guys for the help you gave me in the past.

Here I just wanted to ask you guys a couple of questions that popped up when I recently worked with CC. This is all in respect to the webgl target, so it's about js execution by the browser.

Do remarks and remark blocks slow down execution of the code?

Is ccbGetCopperCubeVariable (and Set) slow, compared to direct variable access?

Are mere function calls slower in the CC object tree structure than on the top script level?

Does a high number of sounds slow down the frame rate excessively? Even when they are paused?

Are there any other bottle-necks I should consider?

And in regards to these non-3d rendering-related speed issues, do you have any suggestion to prevent excessive framerate drop with increasing script complexity, esp. on the level of frequent tasks every 50ms for example.

Is it possible to inject code in the header of the page, from within CC ? The reason why I'm asking is, I'm an old school simple coder, and I like my functions, arrays and some global variables to be accessible from everywhere. That happens automatically if a variable is declared on the top level of the script:

<html><head><script>
var a=123;
var b=0;
test();
alert("a: "+a+" b: "+b);
function test()
{
var b=234;
a=777;
alert("a: "+a+" b: "+b);
}

Some may consider this bad practice, and care must be taken with preventing name-conflicts, but it is much faster and simplifies the whole project IMHO.
Maybe I'm just stupid, but in CC I often end up having to declare the same function in multiple little windows, because they do not see the functions in "do something before first drawing". Then again, arrays, such as myaudio[x] that are declared in the latter, can be seen and used in all CC scripts. I have also noticed, functions, arrays and global variables that are declared in the header section of the page, can be accessed by all CC scripts.

So how do you deal with this issue? Other than to manually edit the page after compiling it in CC to a page that errors out before being manually edited and reloaded.

Yes I know I can keep an edited copy of the page and reload THAT, and just close the tab that CC opens. But still, too many hassles IMHO. Any better ideas?

Thanks!

person icon
okeoke
Registered User
Quote
2023-08-30 08:28:49

Hi Dieter,
Do remarks and remark blocks slow down execution of the code?

To my experience this doesn't slow down code execution, but comments increase file size, which means your application take little bit more time to load, but considering modern connection speeds and processing power I don't think it's something that is noticeable for anyone.
Is ccbGetCopperCubeVariable (and Set) slow, compared to direct variable access?
Are mere function calls slower in the CC object tree structure than on the top script level?

I believe there is no noticeable difference, but you can easily test this using console.time functionhttps://developer.mozilla.org/en.... You can for example, make a loop with 100 - 1000 - 10000 read/write variable actions vs the same amount of direct declaration and see if it makes any difference for you.
And in regards to these non-3d rendering-related speed issues, do you have any suggestion to prevent excessive framerate drop with increasing script complexity, esp. on the level of frequent tasks every 50ms for example.

If you're using webgl you can move processing demanding calculations to separate thread using web workers:https://developer.mozilla.org/en.... This is sort of advanced thing to do - you need to think how to keep main thread and worker in sync, also data transfer between different processes could be an issue. Another thing you can do, try to find out specific parts of your code causing issues using performance tab in devtools:https://www.thisdot.co/blog/perf... and try to optimize this exact parts of the code. Another technique you can use is to separate heavy calculation in time, for example instead of recalculating path for each enemy on a single frame, you can recalculate it for 5 enemies one frame, than 5 enemies next frame and etc. Or if you have two functions which take a lot of time to execute, you run them on odd and even frames so they are never run together on the same frame.
Is it possible to inject code in the header of the page, from within CC ?

I don't think it's possible to inject code directly. But there are a couple of ways to workaround that. You can copy and rename output html file and modify it with your code. You can than serve it using any local webserver, I use node http-server for that purposes:https://www.npmjs.com/package/ht.... Another option is to create a separate script file and add it to html using js:https://stackoverflow.com/questi...

person icon
okeoke
Registered User
Quote
2023-08-30 08:36:21

Maybe I'm just stupid, but in CC I often end up having to declare the same function in multiple little windows, because they do not see the functions in "do something before first drawing".

I sometime just use window global object to provide global access to variables. It's a very bad practice and I don't recommend it:)

person icon
Dieter
Guest
Quote
2023-08-30 10:59:30

Thanks okeoke!

I tjust had this idea, to edit the page html that CC outputs/overwrites each time, so it contains my script, but set it to write-protected in windows. Just did it, and while it kind of worked (a global variable was tested successfully), everything became incredibly slow (like 2 fps) and in the taskmanager the windows explorer went berserk and consumed 40 to 50% cpu constantly, even after closing that browser tab, so I had to kill explorer task, then reopen all my relevant folders. Not sure whether that was related to CC trying to overwrite that write-protected file, but the timely proximity, and that this never happened before, indicates rather strongly so.

person icon
okeoke
Registered User
Quote
2023-08-30 11:54:01

Probably, you can try running web server on the same port coppercube uses before starting coppercube, so it always serves your modified file. Not sure if it works though.

person icon
Dieter
Guest
Quote
2023-08-30 12:26:22

You don't even have to run a webserver (tho I have python ready), CC provides one. All that's needed is a html file in the same folder, displayed in an other browser tab. After CC opens the fresh game10.html, reload your other html file and close game10.html.

But even that, which is fairly simple, I tend to forget between two projects. Well at least when I made a coders-block summer break ^^

But next time I will definitely follow this route and keep things structurally more "overseeable", maintainable and manageable that way.

person icon
okeoke
Registered User
Quote
2023-08-30 13:59:25

Sure you can do that, just need to reload the page manually every time which is a minor inconvenience.

person icon
Dieter
Guest
Quote
2023-08-30 18:39:06

Sure it's doable. It's just, when I forget this and just start a new project from scratch, add a script here and there, then it's too late. I have to follow this method from the beginning on. Sure will do next time.

Right now the spatial 3D audio part is cut to pieces and distributed over various scripts (init, frequent calls, action scripts etc.)

Thanks again for your help RE audio, I couldn't have done it without your hints. Hence I put you in the credits.


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |