wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Warcraft Editing Tools
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-13-2010, 09:47 AM   #106
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 191

Dark_Dragon has little to show at this moment (9)

Default

Quote:
Originally Posted by SFilip
You seem to be underestimating the capabilities of C++ (or rather, its compilers).
Unless you have some giant loop, you needn't worry about speed. Superoptimization can only do you harm in making code harder to read.

> i think they are all by defount set to 0, or am i wrong?
You're wrong, their initial value is unknown, can be anything.

> vex said once that uninitialized variables (globals, locals) leak if called before they are set
Only in Jass.

Your questions seem quite basic, you might want to consider reading a good C++ book or a tutorial. C++ is nothing like Jass.

As for the handles, I didn't quite understand what you need them for, but you can use RtC's handle system (RCHandles) provided in nAPI.

ohh i see, i am now understanding a bit more of how PC works!

few more questions:

> You're wrong, their initial value is unknown, can be anything.
that seems to explain why blizzard did in GUI force us to select array size...
since once a value is applied to an array var it takes memory, until then it does not take memory space! (is what i think)...

since i do not know a value, is there a way (i mean in c++) to detect was variable set "unknown" or does it have a value... my system does not clear mem but uses old indexes for handles so that only neccessary ones have there index.

> Only in Jass.
very bad news for me, coz i never set any array variable and use it always without seting it... for example:

Collapse JASS:
integer MyInt[]

nothing test(handle h) {
   if (MyInt[H2I(h)] == 0)  ... 
}

there are a lot of such lines where actually i only need few indexes, so taking all 8192 slots and looping for each var... ohh btw H2I = GetHandleId-0x100000!

so how big is the leak here?

>
As for the handles, I didn't quite understand what you need them for, but you can use RtC's handle system (RCHandles) provided in nAPI.

yes i already saw the source of VectorAPI! i saw there the use of RCHandles...
through i still dont quite understand what they are, but i guess...

RCHandles is just recycle system for handles?

----------------------------------------------------------------------------------------------------------

through i have only basic c++ in my school, my teacher did not say anything special about "void*" except that it is an pointer to void function!

Code:
long VectorEmpty(long id) {
    vector<int> *thevector = (vector<int>*)GetRCHandle(id, datatype);
	if(thevector == NULL) return false;
	return thevector->empty();
}

void __cdecl VectorDestructor(void* vector_to_destroy) {
    vector<int> *thevector = (vector<int>*)vector_to_destroy;
	if(thevector == NULL) return;
	delete thevector;
}

void InitRtCVector() {
    datatype = RegisterHandleDestructor(VectorDestructor);
}

datatype = ?
if (x == NULL) {return}, i thought in c++ its written as if (x) {delete x}

long VectorEmpty...

returns boolean?
should it be bool VectorEmpty?

as well why is it not (long __cdecl VectorEmpty)?

my funcs like RAbs are all __cdecl!

what i found out about __cdecl is that it will clear the stack after call and its slower but i thought that in jass it would leak if its not converted to c declaration...

------------------------------------------------------------------------------------------------------
i think i have really understanded smth wrong here and sry for asking so much questions each time, ill soon get some tutor or book for c++ to read all from the start... through then i have jass problem lol, coz it leaks on things that c++ does not xD

anyway thanks for all the help and regards!
~DD

EDIT: yeah about what u said, that too much optimization will do me harm! yeah i know and i am not planning to make my code all inlined and do some hardcoding... there are just a few funcs i use a lot so i wanted to optimize them as much as i could... in fact i am using nAPI::RealMap(x);
__________________
Undefined shadow...

Last edited by Dark_Dragon : 04-13-2010 at 09:58 AM.
Dark_Dragon is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-13-2010, 10:17 AM   #107
SFilip
reenignE
 
SFilip's Avatar
 
Join Date: Mar 2006
Posts: 321

SFilip has a spectacular aura about (111)SFilip has a spectacular aura about (111)SFilip has a spectacular aura about (111)SFilip has a spectacular aura about (111)

Send a message via MSN to SFilip
Default

> RCHandles is just recycle system for handles?
Yes, sort of. What exactly do you need?

> since once a value is applied to an array var it takes memory, until then it does not take memory space!
That's not how it works in C++, not sure how Blizzard implemented it in Jass. See Dynamic array.

> so how big is the leak here?
What leak?

> except that it is an pointer to void function!
Well, no, it's just a generic pointer, pointer to something undefined. Can be array pointer, char pointer, struct pointer, class pointer, whatever you need.

> should it be bool VectorEmpty?
No, bool is 1 byte, Jass requires it to be 4 bytes.

> as well why is it not (long __cdecl VectorEmpty)?
No need. C++ uses __cdecl by default, but that can be changed with a compiler parameter IIRC.

> and its slower
Slower compared to what?
The stack has to be cleaned either way, doesn't really matter whether it's the caller or callee that does it (speed-wise).

> i am not planning to make my code all inlined and do some hardcoding... there are just a few funcs i use a lot so i wanted to optimize them as much as i could
See, this is where you are looking at things from a wrong perspective. A C++ compiler will inline everything it can by default. Real optimization is all about not making unnecessary loops or making loops that are longer than they need to be - see Computational complexity theory.
__________________
Want to create your own natives for Jass? Try RtC project's nAPI
SFilip is offline   Reply With Quote
Old 04-13-2010, 12:06 PM   #108
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 191

Dark_Dragon has little to show at this moment (9)

Default

Quote:
Originally Posted by SFilip
> RCHandles is just recycle system for handles?
Yes, sort of. What exactly do you need?

> since once a value is applied to an array var it takes memory, until then it does not take memory space!
That's not how it works in C++, not sure how Blizzard implemented it in Jass. See Dynamic array.

> so how big is the leak here?
What leak?

> except that it is an pointer to void function!
Well, no, it's just a generic pointer, pointer to something undefined. Can be array pointer, char pointer, struct pointer, class pointer, whatever you need.

> should it be bool VectorEmpty?
No, bool is 1 byte, Jass requires it to be 4 bytes.

> as well why is it not (long __cdecl VectorEmpty)?
No need. C++ uses __cdecl by default, but that can be changed with a compiler parameter IIRC.

> and its slower
Slower compared to what?
The stack has to be cleaned either way, doesn't really matter whether it's the caller or callee that does it (speed-wise).

> i am not planning to make my code all inlined and do some hardcoding... there are just a few funcs i use a lot so i wanted to optimize them as much as i could
See, this is where you are looking at things from a wrong perspective. A C++ compiler will inline everything it can by default. Real optimization is all about not making unnecessary loops or making loops that are longer than they need to be - see Computational complexity theory.

> Yes, sort of. What exactly do you need?

yeah recycle system is fine, i did not need anything more but was not sure if it was a recycle system. now i know :)

---------------------------------------------------------------------------------------------

> Dynamic Array Alloc!

yeah ill go and check it out!

---------------------------------------------------------------------------------------------

> What leak?

one that vex said leaks in jass!

Code:
// btw this is "cJass" not "c++"
integer Leak[] // never init this var (until it gets in if check)

nothing init() {
  // this if is executed before i set it to "7"
  if (Leak[0] == 0) {
    Msg("a big leak?");
    Leak[0] = 7;
  }
}
---------------------------------------------------------------------------------------------

> Well, no, it's just a generic pointer, pointer to something undefined. Can be array pointer, char pointer, struct pointer, class pointer, whatever you need.

ahh i see, thanks thats one great feature!
---------------------------------------------------------------------------------------------

> No, bool is 1 byte, Jass requires it to be 4 bytes.

i see!
---------------------------------------------------------------------------------------------

> No need. C++ uses __cdecl by default, but that can be changed with a compiler parameter IIRC.

did not know, so basically i dont need to write __cdecl... k!
---------------------------------------------------------------------------------------------

> Slower compared to what?
The stack has to be cleaned either way, doesn't really matter whether it's the caller or callee that does it (speed-wise).

k, i think that i misunderstanded what __cdecl does, now it seems more clear... anyway its c++ i am not that crazy to code in _asm + i would need to learn asm first... just ignore this part xD
---------------------------------------------------------------------------------------------

thanks for the link and i did not know c++ inlines stuff by default, thats really one awesome feature! so basically nAPI::RealMap is inlined coz its one line (i know it does not have to be) coz i added inline before RealMap but it did not compile so i guess it cant be inlined... anyway i really dont care for such performances... ill just code the way u and rest of good coders do! nanoseconds do not matter here lol!

============================================================

once again thanks for all the answers i got all of this stuff now and will check links that u give me. i tested my dll and all works fine!

Regards!
~DD

EDIT: i could have not found any variable in struct W3UNITINFO that could return unit scale (size)...

i guess it is impossible to code it then, right?
__________________
Undefined shadow...

Last edited by Dark_Dragon : 04-13-2010 at 02:25 PM.
Dark_Dragon is offline   Reply With Quote
Old 04-13-2010, 12:20 PM   #109
<?White-Tiger?>
User
 
<?White-Tiger?>'s Avatar
 
Join Date: Apr 2008
Posts: 31

<?White-Tiger?> has little to show at this moment (0)

Default

about inlining RealMap etc:
Just use Define ;)
Code:
/*	long RealMap(float f) {
		return *(long*)&f;
	}
	float RealGet(long l) {
		return *(float*)&l;
	}//*/
	#define RealMap(arg) *(long*)&arg
	#define RealGet(arg) *(float*)&arg
<?White-Tiger?> is offline   Reply With Quote
Old 04-13-2010, 01:45 PM   #110
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 191

Dark_Dragon has little to show at this moment (9)

Default

Quote:
Originally Posted by <?White-Tiger?>
about inlining RealMap etc:
Just use Define ;)
Code:
/*	long RealMap(float f) {
		return *(long*)&f;
	}
	float RealGet(long l) {
		return *(float*)&l;
	}//*/
	#define RealMap(arg) *(long*)&arg
	#define RealGet(arg) *(float*)&arg

k thanks for suggestion!
__________________
Undefined shadow...
Dark_Dragon is offline   Reply With Quote
Old 04-15-2010, 06:27 AM   #111
MindWorX
Level 1 Neothelid


Tools Moderator
 
Join Date: Mar 2004
Posts: 254

Submissions (2)

MindWorX has a spectacular aura about (147)

Default

Quote:
Originally Posted by <?White-Tiger?>
about inlining RealMap etc:
Just use Define ;)
Code:
/*	long RealMap(float f) {
		return *(long*)&f;
	}
	float RealGet(long l) {
		return *(float*)&l;
	}//*/
	#define RealMap(arg) *(long*)&arg
	#define RealGet(arg) *(float*)&arg
Please test your defines before posting, the reason we use functions is because those defines won't work when calling a function.
Take this example:
Code:
#define RealGet(arg) *(float*)&arg
float* ReturnFloat(float f) { return &f; }
void main() {
    RealGet(ReturnFloat(1.00f));
}
That won't compile.

EDIT:
Also, if you intend to post your RealGet, please rename it RealGetReturn instead to avoid confusions, as it's only needed when getting a value returned from a blizzard native, and not when reading a Jass::real argument in custom natives.

Last edited by MindWorX : 04-15-2010 at 04:18 PM.
MindWorX is offline   Reply With Quote
Old 04-15-2010, 10:09 AM   #112
<?White-Tiger?>
User
 
<?White-Tiger?>'s Avatar
 
Join Date: Apr 2008
Posts: 31

<?White-Tiger?> has little to show at this moment (0)

Default

Quote:
Originally Posted by MindWorX
Please test your defines before posting, the reason we use functions is because those defines won't work when calling a function.
Take this example:
Code:
#define RealMap(arg) *(long*)&arg
float* ReturnFloat(float f) { return &f; }
void main() {
    RealMap(ReturnFloat(1.00f));
}
That won't compile.
What do you mean? I see no use of this^^ There 2 things wrong... first everything has no use there^^
2. u use a float pointer and not a float so that's wrong... This won't work with your functions too^^

Quote:
EDIT:
Also, if you intend to post your RealGet, please rename it RealGetReturn instead to avoid confusions, as it's only needed when getting a value returned from a blizzard native, and not when reading a Jass::real argument in custom natives.
Sure that reals as argument of an custom native uses a other way? I mean they are Jass::real so it's handled as int/long and not as float.But i will test it by my own and edit this post here.

Edit...
oh.... yeah... you're right ;) So...assumed i did understood and I'm right, it means the float is passed as a pointer so that we can change it in our native.
However, everything that passes our native is therefore nothing what could be changed. That's the reason why we get's a float pointer but put's a normal float (handled as long)

So that's the reason why there are problems with string natives.. the string(everything?) passed to natives can be changed but strings(everything?) received from natives can't be changed. I wish I had better regarded the examples and noticed everything :D

And about my defines... y.. they aren't multi-talents, so RealMap(123.456) won't work just because 123.456 is a constant value etc... but i will use my defines as often i can.

Last edited by <?White-Tiger?> : 04-15-2010 at 02:20 PM.
<?White-Tiger?> is offline   Reply With Quote
Old 04-15-2010, 03:48 PM   #113
MindWorX
Level 1 Neothelid


Tools Moderator
 
Join Date: Mar 2004
Posts: 254

Submissions (2)

MindWorX has a spectacular aura about (147)

Default

I wrote the wrong example, i was referring to RealGet, fixed.
And yes, the problem with strings is something similar to what's going on with floats.
MindWorX is offline   Reply With Quote
Old 04-15-2010, 05:24 PM   #114
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 191

Dark_Dragon has little to show at this moment (9)

Default

Quote:
Originally Posted by MindWorX
I wrote the wrong example, i was referring to RealGet, fixed.
And yes, the problem with strings is something similar to what's going on with floats.

yeah i know and thats why i said thanks for suggestion as in some cases i have simply variable float "fl"

then i dont need to call RealMap so i can indeed just call a define, however in the end i decided to call nAPI::RealMap... dont wanna use defines coz really i dont care about c++ speed of 1 func...

anyway RTC is awesome i already wrote my natives and they work, nice handle recycle engine, i got it up and running!

Greets!
__________________
Undefined shadow...
Dark_Dragon is offline   Reply With Quote
Old 04-15-2010, 05:44 PM   #115
SFilip
reenignE
 
SFilip's Avatar
 
Join Date: Mar 2006
Posts: 321

SFilip has a spectacular aura about (111)SFilip has a spectacular aura about (111)SFilip has a spectacular aura about (111)SFilip has a spectacular aura about (111)

Send a message via MSN to SFilip
Default

Actually, the (most likely) reason why real is passed as a pointer is because float parameters are pushed to the floating point stack by default. Using a pointer allows you to bypass that and pass them the same way other parameters are passed.
__________________
Want to create your own natives for Jass? Try RtC project's nAPI
SFilip is offline   Reply With Quote
Old 04-16-2010, 04:41 PM   #116
Komaqtion
User
 
Komaqtion's Avatar
 
Join Date: Jan 2009
Posts: 144

Komaqtion is on a distinguished road (10)

Send a message via MSN to Komaqtion
Default

Ok, so I downloaded this a few days ago, and it's been working fine :D

But now, after I came home from school, I can't test my map anymore.. :(

I have tried both clicking the "Test Map" button and started the "launch.exe" from the RtC folder but nothing works. The small "Reinventing the Craft" window comes up for a few seconds, and then I get an error saying something like "Warcraft III has stopped working" :S

WHY ?! :(
__________________

Komaqtion is offline   Reply With Quote
Old 04-16-2010, 05:46 PM   #117
<?White-Tiger?>
User
 
<?White-Tiger?>'s Avatar
 
Join Date: Apr 2008
Posts: 31

<?White-Tiger?> has little to show at this moment (0)

Default

it will be fixed soon. It's a known problem.
But.. what OS you have? Windows Vista or 7?
<?White-Tiger?> is offline   Reply With Quote
Old 04-17-2010, 08:44 AM   #118
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 191

Dark_Dragon has little to show at this moment (9)

Default

Hi guys, its me again!

i have a question!

how do you execute or evaluate jass "code" type? its a func pointer right? but how do i cast long to "void (*pf)(void)" or (long (*pf)(void))... then i simply call that func normally and that should be it right?

ohh yeah its long or void coz its a jass ptr func so it returns nothing or long...

Regards!
__________________
Undefined shadow...
Dark_Dragon is offline   Reply With Quote
Old 04-17-2010, 07:17 PM   #119
MindWorX
Level 1 Neothelid


Tools Moderator
 
Join Date: Mar 2004
Posts: 254

Submissions (2)

MindWorX has a spectacular aura about (147)

Default

Quote:
Originally Posted by Dark_Dragon
Hi guys, its me again!

i have a question!

how do you execute or evaluate jass "code" type? its a func pointer right? but how do i cast long to "void (*pf)(void)" or (long (*pf)(void))... then i simply call that func normally and that should be it right?

ohh yeah its long or void coz its a jass ptr func so it returns nothing or long...

Regards!
You can't just call a function like that.
MindWorX is offline   Reply With Quote
Old 04-17-2010, 07:21 PM   #120
Komaqtion
User
 
Komaqtion's Avatar
 
Join Date: Jan 2009
Posts: 144

Komaqtion is on a distinguished road (10)

Send a message via MSN to Komaqtion
Default

Quote:
it will be fixed soon. It's a known problem.

Oh, ok...

Quote:
But.. what OS you have? Windows Vista or 7?

Windows Vista 32-bit :D
__________________

Komaqtion is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 07:24 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2018, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services