HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS Challenge

11-29-2003, 03:48 PM#16
weaaddar
Thats not true AIAndy Dialogs and certain other object types act like pointers.

What is this pointer arithmatic you speak of?
11-29-2003, 06:18 PM#17
Vidstige
Quote:
Originally posted by weaaddar
Thats not true AIAndy Dialogs and certain other object types act like pointers.
Try think pointers as in C/C++, which you can use to make a total mess of your memory:gsmile:.
Quote:
What is this pointer arithmatic you speak of?
If the language doesn't support structs and you have access to some kind of indexed memory you can manually store your structs in memory. That is you point somewhere in memory and writes a bit of your struct there, then increase the pointer to point after where you written, and write the next part of the struct where the pointer now points.

If this seems confusing, keep in mind that people learning C/C++ quite often manage to crash there programs because they screw up there pointers. :ggani:
11-29-2003, 06:37 PM#18
AIAndy
Quote:
Originally posted by weaaddar
Thats not true AIAndy Dialogs and certain other object types act like pointers.

What is this pointer arithmatic you speak of?
Dialogs are derived from handle. If you look at the beginning of common.j you will see that most of the data types are in fact handles. But all those cannot be freely dereferenced so their usage is limited.

Pointer arithmetic has been explained by Vidstige. If you use something like my_struct.my_struct_field in a programming language that supports that then the Compiler will translate that in a pointer computation. He knows what offset from the beginning of the struct my_struct_field can be found and my_struct is given by a pointer to the beginning of the struct. Now the Compiler can compute that by my_struct + my_struct_field_offset.
11-29-2003, 06:37 PM#19
weaaddar
Ah I've been spoiled with higher level programming languages like C# & Java.

Interesting Idea.

Also you can screw with the widget extended object. Not very useful but you can cause war3 to consider an item a hero if you play with the widgets correctly.

(Equiping a hero item crashes the game wierd eh?)
11-30-2003, 12:31 AM#20
TheEpigoni
Guys everything you're discussing is irrelevant, and the reason this is possible is that it's irrelevant. The way AIAndy described this is very intelligent and easy to do (as easy as something like this can be done at least =) ). The whole idea is that we don't need pointers etc, we sortof transform integers into pointers, which is exactly how regular pointers work, they're just integers representing a chunk in memory. And by laying asside an array for just that purpose, we have that chunk of memory. I won't go on because that will be giving away the challenge but you guys have to get past Jass's shortcommings and realize we're not trying to find a way to use pointers and handles or whatnot, we're creating something completely new (which since AI has said it is possible to do) with what we know Is possible in Jass.
11-30-2003, 10:40 PM#21
Vexorian
I would like to understand at least what are we supposed to do. it seems that this is not my strenght
12-01-2003, 12:01 AM#22
AIAndy
The main part that needs to be done is the heap. This is a chunk of memory which in our case will be an array. This memory should be available for different purposes.
To coordinate its use, every trigger/thread that wants to use a part of that memory needs to call HeapNew. He passes the length of the memory piece he wants and gets a pointer to the beginning of that memory. That memory is now reserved and must not be handed out by HeapNew again.
After the trigger no more needs that memory, he calls HeapDelete. He passes the pointer that he got from HeapNew and the length he passed. This labels that memory part as free again and HeapNew may now hand it out again.
To access a reserved piece of memory, a trigger calls HeapGet and HeapSet. The first returns the value at a specific point, the second sets it.

An example:
You want to store an object on the heap that consists of 2 integers.
First you need to reserve a part of that length:
local integer my_pointer = HeapNew(2)

Now we can put our 2 integers in there, lets assume they are 7 and 83:
call HeapSet(my_pointer, 7)
call HeapSet(my_pointer + 1, 83)

Now after some time you don't need that object any more:
call HeapDelete(my_pointer, 2)

For linked lists just search in Google and you will find loads of explanations.

If you have further questions, feel free to ask them.
12-01-2003, 01:32 AM#23
silverdrake
Quote:
Originally posted by AIAndy
That reminds me that it would be great if someone would write a precompiler that takes high level code that allows for classes and structs and translates it into low level JASS with pointer arithmetic using the heap.
[/b]


I have been wanting to do this for a long time. You could implement structs without a heap, ant it would still be very useful. Supporting this generic heap would also be cool, but you would be limited to structs with integer fields, unless you also had a string heap, a real heap, etc.

It would also be nice to have #include functionality in a precompiler, even if it didnt do anything fancy like merge globals.

While we're at it, might as well throw in multidimensional arrays, for loops, += operators, implicit typecasting, multiple inheritance, polymorphism, reflection, unions, bitfields, templates...
12-01-2003, 10:28 AM#24
TheEpigoni
Submission sent, mine is the one from [email protected].
12-01-2003, 10:42 AM#25
AIAndy
By using the return bug you can convert handles to integer and vice versa. That allows to store most game objects on the heap. I have not tried a real/integer conversion but it might work too. I guess string does not work but I am not sure. Even if it doesn't then all it needs is a string heap and you have one for all types.

A precompiler that does simple things that do not need parsing would be great already. I especially thought of an extended include feature that reads data from a table and allows to input that in repeated code. That way I could at last separate data from code in AMAI.
12-02-2003, 12:56 AM#26
weaaddar
return bug?
12-02-2003, 04:27 AM#27
AIAndy
War3 does not check the return type in ifs if there is a return after that if. That means you can return any type regardless of what the function declares it returns.
So code like this will work:

function Handle2Int takes handle h returns integer
if h != null then
return h
endif
return 0
endif

That can be used to store any handle derivative (unit, location, ...) in the integer heap.
12-03-2003, 03:21 PM#28
Vexorian
I finnally understood the objective, in fact i think that it won't matter who the winner is, this is going to help the community a lot, I can see lists, 2d arrays, sets and a lot of other useful stuff in the future
12-03-2003, 11:58 PM#29
Cubasis
Hey all,

This is an awesome idea, i already pointed it to Ganon which needed exactly something like this for his Project.

Basicly he'll have tile-based keyboard-control system which will work exactly like the old zeldas, he's done a incredible job at compiling tons of data from the games, how stuff works, level-layout, tile-possibilities and all.

The easiest way to do this is ofcourse to do a 2d-integer map of each room where each element represent one tile over the 8x10 (or sumtin) "room". And each tile could hold different properties, as a movable box, enemy, player, button, whatever.

But as he didn't know much about jass, he guessed it had 2d-arrays (or more dimensions)...and even be able to have arrays as parameters in methods, which wc3 obviously does not support. He also could have gone with multiple arrays, but working with them would need extensive if-then-else as he will likely have 100's of rooms. He could also have just made one giant array, with the rooms stacked into it, but that would be hard to manage (although similar to the current "challenge"), and the array-size limit isn't all that high (and i know one can raise it easily, but that doesn't neccessarily help).

So basicly, this is PERFECT for his need, atleast as the pointers can point to 4294967296 slots (just needing enough arrays in the system) which should be very sufficient for his needs, and the easy-ness to handle Room starts, he'd just set them all into memory at start, and put each rooms starting pointer in a normal array for further use.

Anyways... he'll be waiting anxious for a result from this challenge.

Just to allow you to realize how useful this is :D.

Cubasis

EDIT: Grammar + ..... AIAndi, do you never check your Private Messages?? :D, i really need a answer as soon as possible.
12-04-2003, 12:14 AM#30
weaaddar
nd arrays have always been possible.
The main limiting agent is unfortuantly the cap which though nicely raised to 8096 is still a bummer
I use something like this for 2d arrays
Code:
function index takes integer x, integer y returns integer
return(x*(ylimit)+y)
endfunction