Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 730 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Usage of structs? #145397
08/03/07 05:55
08/03/07 05:55
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
I know what a struct is, I just don't know how I would use it in a script. Can someone point me in the right direction here?

Well, I did write this small test code to test my knowledge of the syntax:

Code:

#include <acknex.h>
#define PRAGMA_ZERO

var showint1;
var showint2;

typedef struct
{
int test1;
int test2;
char test3[10];
} TEST;

TEST* here_we_go=
{
test1= 7;
test2= 7;
test3= "Hello, World!";
}

FONT* sys_font= "Terminal#12";

PANEL* show_struct_values=
{
digits (320,240,"Struct value 1= %9.0f",sys_font,1,showint1);
digits (320,250,"Struct value 2= %9.0f",sys_font,1,showint2);
flags= visible;
}

void exit_()
{
sys_exit(NULL);
}

function main()
{
screen_color.red= 1;
video_mode= 8;
video_screen= 1;
on_esc= exit_;
showint1= here_we_go.test1;
showint2= here_we_go.test2;
}



but you could just as easily define the vars and display them with the panel.

EDIT: Oops! Sorry, wrong forum! I thought I was in Lite-C Scripting! Could someone move this?

Last edited by MrCode; 08/03/07 06:03.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Usage of structs? [Re: MrCode] #145398
08/03/07 06:28
08/03/07 06:28
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
i used structs to create a "QUATERNION" type which can be passed to quaternion functions that i wrote. it's much easier than handling var array's, and much more intuitive to work with (if you know what you're doing with quaternions, my_quat.w/x/y/x makes much more sense than my_quat[0/1/2/3]).

i also used structs to create a "PHYS_ENT" type. these contained a pointer to an entity; two quaternions (containing orientation and angular velocity); a velocity vector; floats for mass, elasticity, coefficient of friction, moment of inertia; and lastly a PHYS_ENT pointer called "next_phys".

this helped in making my own custom physics engine. the pointer to "next_phys" allowed me to use linked lists to keep track of which PHYS_ENT's were enabled and which were disabled. it also meant i could create force-applying functions (and similar) that only need to be passed a force, position, and pointer to a PHYS_ENT, and then the function knows how to use and change each of the parameters within the PHYS_ENT struct.

additionally, every object in lite-C -- ENTITY, VIEW, PANEL, MATERIAL, PARTICLE, VECTOR, ANGLE etc -- is a struct. ENTITY contains things like var skill[100], ANGLE pan, VECTOR x, and all those other things that belong to an entity. if you need other stuff, create a struct. i created PHYS_ENT because you can't access local variables (or local structs) from one action in another, so i gave PHYS_ENT everything extra that other PHYS_ENTs would need access to.

linked lists are very useful. they are a bit like arrays except they can change in length, and new members can be stuck in anywhere without affecting others.

for example, i had a PHYS_ENT called phys_enabled, and another called phys_disabled. i also had an array of 128 global "phys_ent"s. at game start, phys_disabled's pointer "next_phys" was pointed to the "phys_ent[0]". a loop made each phys_ent point to the next one (don't confuse phys_ent, the array, with PHYS_ENT, the type of the array). any PHYS_ENT in the "phys_disabled" list could be found by checking a PHYS_ENT's next_phys, and then checking their next_phys, and so on and so forth.

i had a function that gets called to enable a physics entity, and that would do so by just grabbing the first PHYS_ENT in the phys_disabled list (after the actual "phys_disabled" PHYS_ENT, of course), pointing it to the ENTITY i wanted to enable and putting it in the phys_enabled list. a separate function which ran 60 times a second would cycle through every PHYS_ENT in the phys_enabled list and allow them to move, react to collisions, etc.

more info on linked lists can be found in this example: http://www.coniserver.net/ubbthreads/sho...4550db041639079

i hope this is helpful,

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: Usage of structs? [Re: JibbSmart] #145399
08/03/07 07:06
08/03/07 07:06
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Quote:


ENTITY contains things like var skill[100], ANGLE pan, VECTOR x, and all those other things that belong to an entity.




Yes, but how, for example, does ANGLE actually rotate the entity? I understand the concept of a struct being an object consisting of various variables and pointers, but I don't know how you'd use say:

Code:

typedef struct
{
float rotate;
} SPIN;



To actually spin an object.


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Usage of structs? [Re: MrCode] #145400
08/03/07 07:21
08/03/07 07:21
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
ANGLE doesn't rotate the entity. the engine has built in functions which we can't see that go through each entity every frame (probably through a linked list or something similar) and use the contents of the entity's "pan", "tilt" and "roll" to orientate the entity.

my custom physics would cycle through my PHYS_ENTS, check their quaternion "quat" or something, and use my functions to convert that to an euler angle that the engine understands and passing it to the entity's pan/tilt/roll.

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: Usage of structs? [Re: JibbSmart] #145401
08/03/07 20:21
08/03/07 20:21
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Quote:

more info on linked lists can be found in this example: http://www.coniserver.net/ubbthreads/sho...4550db041639079<br />
<hr /></blockquote><font class="post">




Aah! Too much code!

Other than that, I get the basic idea.

Perhaps I should read up on some C/C++ programming books (or online) to "educate" myself.

Last edited by MrCode; 08/03/07 20:29.
Re: Usage of structs? [Re: MrCode] #145402
11/02/07 17:27
11/02/07 17:27
Joined: Nov 2005
Posts: 94
Texas
3
3Dski Offline
Junior Member
3Dski  Offline
Junior Member
3

Joined: Nov 2005
Posts: 94
Texas
Doesn't look like this thread has been active in awhile, but I'll put in my two cents concerning the general use of structs:

First, they are simply a way of holding realated data to carry out a category of tasks, with the type and name of the sturcture describing the purpose; COLOR, POSITION, etc.

Their are a number of benefits connected to the use of structs. They help organize your data and make your code more readable. Furthermore, they help with function argument passing in that, as opposed to passing a bunch of separate variables to a function, you can pass the a single struct* that contains all the needed items. The Windows API makes heavy use of this, where an API call requires the passing of a specific struct that may it might initialze. Then, other API calls would require the same struct to carry out further processing. Instead of having to examine a large number of separate variables, a structure that contains all the data needed for processing, can have its elements updated and can be examined or used for later processing.

So an advantage of using structs with functions is, you don't to worry about remembering the number of parameters to pass to a function, but only know the type of struct it requires. One could argue that this is alos more efficient, in that you are only pass a single struct*, as opposed to a handful of variables being placed on the call stack when the function is called.

Additionally, functions can only return one value, or left to manipulate global variables. By working with data in a struct, the function can return a single struct, or work with a global struct, to alter mulitple pieces of data, which minimizes the number of global variables and the possibility of name clashes; point.x and position.x will not overwrite one anothers values unexpectedly, thought both structs have an "x" element.

Not the best place to expound on the topic, but the post was here, so I have. : )

Re: Usage of structs? [Re: 3Dski] #145403
11/03/07 07:10
11/03/07 07:10
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
here is a question:
i have structure

typedef struct
{
ENTITY* model;
var keyX;
var keyY;
}ChaR;

ChaR MH,GH;

how could i get keyX of one of MH or CH, if i only have pointer to model?


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Usage of structs? [Re: VeT] #145404
11/03/07 07:47
11/03/07 07:47
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
I'd advice you to store pointer to a structure in entity skill

Re: Usage of structs? [Re: Shadow969] #145405
11/04/07 13:41
11/04/07 13:41
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
typedef struct
{
***
ROACH* body;
}PILOT;


typedef struct
{
***
PILOT* driver;
}ROACH;

any ideas about this? :-)


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Usage of structs? [Re: VeT] #145406
11/04/07 14:01
11/04/07 14:01
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
In this case work with void* as universal type.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1