1 registered members (AndrewAMD),
946
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: GSVector
[Re: VeT]
#261233
04/16/09 13:50
04/16/09 13:50
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Okay, here i am... As i see, post is long, so please, read carefully, its not hard So, i have a struct
typedef struct {
var s;
var i;
var j;
var step_max;
var step_left;
} CHARACTER;
Then, i have a text file, where info about CHARACTERs is stored.. For example, i have info about 2 characters: first with s=1; i=4; j=2;, second one with s=1; i=5; j=5; But, as character model are not created immideately, i need to store that info in vector. So i read my file:
players_number = file_var_read(fhandle);
vPlayers = createGSVector();
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
var i;
for (i=0; i<players_number; i++)
{
tempChar.s = file_var_read(fhandle);
tempChar.i = file_var_read(fhandle);
tempChar.j = file_var_read(fhandle);
tempChar.step_max = file_var_read(fhandle);
tempChar.step_left = file_var_read(fhandle);
insertIntoGSVector(vPlayers,tempChar);
}
On this step everything looking okay, and debugger shows that vector vPlayers consist of 2 elements, thats right Next, i create 2 players models (first, in coordinate s=1; i=4; j=2; , second - in s=1; i=5; j=5;) and i want to load info about their step_left from vector So, i add function
void GetPlayerInfo(var s,var i, var j)
{
ENTITY* tempEnt;
int num;
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
while(sizeOfGSVector(vPlayers)==0) {wait(1);}
very_very_temp = sizeOfGSVector(vPlayers);
wait(1);
for(num=0; num<sizeOfGSVector(vPlayers); num++) {
very_very_temp = num;
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));
if ((tempChar.s == s) && (tempChar.i == i) && (tempChar.j == j))
{
tempEnt = ReturnModelPointer (TypeModel,s,i,j);
tempEnt.sPlayerStepsMax = tempChar.step_max;
tempEnt.sPlayerStepsLeft = tempChar.step_left;
very_very_temp = tempEnt.sPlayerStepsLeft;
// eraseFromGSVector(vPlayers,num);
tempChar = NULL;
break;
}
tempChar = NULL;
}
}
In this function i go through vector, take elements one-by-one and compare element's s,i,j with models s,i,j. If true, then i load step_max to entity's skill, if not, i'm proceeding to next element. Now, the problem: If i have first entity with coordinates 1,5,5, and first element of vector has 1,5,5, then everything works okay. BUT, if i compare first entity's 1,4,2 with first element with 1,5,5, then i come to the second vector's element (1,4,2) and in string
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));
i got a crash I tried to say it as simple as possible
|
|
|
Re: GSVector
[Re: KDuke]
#261245
04/16/09 14:18
04/16/09 14:18
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Hm... now that I'm finally at the point to actually implement GSVector I'm at loss. Although I've been using Vectors in C++ before I can't get this one running. A documentation is really needed. I already managed to insert several values though I only can use getFromGSVector(myVector, 0); As soon as I use another position the engine crashes. greetings KDuke mmm... yes, something like this.. int* crashes for me, looking like i need work with it
|
|
|
Re: GSVector
[Re: VeT]
#261298
04/16/09 19:56
04/16/09 19:56
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
Hi VeT, using a code similiar to this:
for(i=0; i<sizeOfGSVector(scheduler); i++) {
scheduleTask = (SCHEDULETASK*)(getFromGSVector(scheduler,i));
}
works fine in several projects of mine. Just when I directly access a position in the vector I need to use an int* as it is described in the documentation. But are you sure to store your values like that in a vector? In worst case you have to run through the whole vector to get back your values. Wouldn't it be better to store your struct in a hashmap and then access it directly with a unique key? In my current projekt (point&click adventure) I have hundreds of useable objects and each of them has additional data stored in structs ... I store those structs in a hashmap and as a key I use a unique ID that is written in string1 of the entity. So if I have the entity I can directly access all additional data by using the ID to get the struct out of the hashmap. Regards, Pegamode.
|
|
|
Re: GSVector
[Re: pegamode]
#261305
04/16/09 20:35
04/16/09 20:35
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
//using a code similiar to this: In your case, i is integer or var?
You see, i save all info about land parts (name of model and angle) and models (name of model, angle and HP) in different matrixes in *.lvl file (just text file). Really, i'm able to add matrix with steps_max, steps_current, types of weapons and so on... but its looking like better to save info about charackers in strings after matrixes.
|
|
|
Re: GSVector
[Re: pegamode]
#261370
04/17/09 08:41
04/17/09 08:41
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Hm.. so, you read/write text from file dynamically? F.e, you read door statement, then player change it, and you write it in a file again? I chose another way: i read one time info about models from matrixes and store(and change) it there.. while level saved, i save matrixes into file one time. But between reading info and creating models i need to store info about players somewhere else, like in your vector. //In my case i is an int ... But what about KDuce's note Thank you very much for the documentation and the code examples.
Though I gotta mention one thing about the position variable! It not only has to be of type int it HAS to be int*
EDIT: please mention that in the documentation!
I tried this way:
void GetPlayerInfo(var s,var i, var j)
{
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
while(sizeOfGSVector(vPlayers)==0) {wait(1);}
diag("\n[!!!] Vector size:");
diag_var(" size: %6.3f",sizeOfGSVector(vPlayers));
int num;
for(num=0; num<sizeOfGSVector(vPlayers); num++) {
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));
diag("\n[!!!] Vector:");
diag_var(" s: %6.3f",tempChar.s);
diag_var(" i: %6.3f",tempChar.i);
diag_var(" j: %6.3f",tempChar.j);
}
}
and this gives me [!!!] Vector size: size: 2.000 [!!!] Vector: s: 1.000 i: 5.000 j: 5.000 Error E1513: Crash in GetPlayerInfo Program aborted Now, if i change order of storing values in vector, it returns [!!!] Vector size: size: 2.000 [!!!] Vector: s: 1.000 i: 4.000 j: 2.000 Error E1513: Crash in GetPlayerInfo Program aborted So, from all this i can say that insertIntoGSVector works fine, but i may deal with getFromGSVector Please, can you gibe more info about getting values from vector?
|
|
|
Re: GSVector
[Re: VeT]
#261377
04/17/09 09:31
04/17/09 09:31
|
Joined: Mar 2009
Posts: 112 Germany
KDuke
Member
|
Member
Joined: Mar 2009
Posts: 112
Germany
|
Hi VeT! In the meantime I've encountered problems with simply using int* as well. I had the same trouble as you have. Tried different things until I came (I think at least so, I don't have my source at hand right now) to a point where I noticed that it is working when I use a global int for the getFromGSVector index. If you try to use a local variable getFromGSVector it needs to be of datatype byte* because if you use
int* example = 0;
example ++;
the value of example will be 4 as an int is 4 bytes big and therefore the pointer is increased in multitudes of four. Thats how it is working for me right now. But maybe pegamode just should check his source for getFromGSVector. It indeed behaves strange in some situations. greetings K-Duke
Using A7 Free Click and join the 3dgs irc community! Room: #3dgs
|
|
|
|