Community
Message Board

Chat room - users
Game Over
( 394431 downloads)
Work In Progress
( 523201 downloads)
Links

Code Exchange
Downloads
Tutorials
Add to Favourites

Submit news

DIV ARENA FORUMS
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: Two for one offer
dom cook
Div Pro
******




Posts: 386
Registered: 4-3-2016
Member Is Offline


[*] posted on 2-6-2019 at 05:31 AM
Two for one offer


Here are a couple of useful snippets.

1) Ever wanted to be able to make a copy of a struct without assigning all the values individually? Well, now you can.

2) Did you know DIV can do 2d arrays (tables)?

SNAP0001.gif - 164kB
View user's profile View All Posts By User
Vortigano
DIV Regular
***




Posts: 237
Registered: 12-1-2017
Location: Ciudad de Buenos Aires, Argentina
Member Is Offline


[*] posted on 10-6-2019 at 06:30 PM


Quote: Originally posted by dom cook  

1) Ever wanted to be able to make a copy of a struct without assigning all the values individually? Well, now you can.



Do you mean something like C language memcpy?
View user's profile View All Posts By User
dom cook
Div Pro
******




Posts: 386
Registered: 4-3-2016
Member Is Offline


[*] posted on 11-6-2019 at 07:47 AM


Possibly, I don't know much C.

The motivation behind this was to explore the possibilities of passing structs to functions by reference rather than by index. In general this is not really needed but in cases where one might want to copy or reset all the values in a large struct it can be useful especially as it does not need to be written individually for specific structs.
View user's profile View All Posts By User
Vortigano
DIV Regular
***




Posts: 237
Registered: 12-1-2017
Location: Ciudad de Buenos Aires, Argentina
Member Is Offline


[*] posted on 11-6-2019 at 07:45 PM


You're going to share a method for passing structures? That'd be great!
I usually use: passing structure by reference, and use the return() statement only to verify errors or for "integer to integer" boolean operations.
View user's profile View All Posts By User
dom cook
Div Pro
******




Posts: 386
Registered: 4-3-2016
Member Is Offline


[*] posted on 11-6-2019 at 08:28 PM


Quote: Originally posted by Vortigano  
You're going to share a method for passing structures? That'd be great!

I thought I already did. But on closer inspection I see I neglected to upload the file.

I think this is it.


Attachment: copystructure.PRG (2kB)
This file has been downloaded 755 times


[Edited on 11-6-2019 by dom cook]
View user's profile View All Posts By User
dom cook
Div Pro
******




Posts: 386
Registered: 4-3-2016
Member Is Offline


[*] posted on 11-6-2019 at 08:40 PM



The code's a bit confusing as it does two things, the other being using 2d arrays (which I didn't know Div supported.
The copy_structure process at the bottom is the relevant bit. It takes the address of the struct and the size of each entry and copies one entry's data into another. Because there is no need to specify each field, this function can be reused for any struct.
Anyway I suspect this isn't quite what you were expecting but, maybe it's useful to you.

[Edited on 11-6-2019 by dom cook]

[Edited on 11-6-2019 by dom cook]
View user's profile View All Posts By User
Vortigano
DIV Regular
***




Posts: 237
Registered: 12-1-2017
Location: Ciudad de Buenos Aires, Argentina
Member Is Offline


[*] posted on 12-6-2019 at 12:44 AM


Wow, the map_put function g[bbc [...]], very ingenious ^u^
About the function "copy_struct", the power of "sizeof" is the law :P
I also saw that you use arrays with embedded strings, that's something I recently also discovered ... because I've always used Div's String type more often, in order to be able to use the div string functions.
View user's profile View All Posts By User
MikeDX
DIV Nerd
*********


Avatar


Posts: 8388607
Registered: 25-2-2016
Member Is Offline


[*] posted on 12-6-2019 at 07:10 AM


I'm going to have to look into this. it may be possible to abstract divs string type to use floats as I've had an idea about var length since string is a pointer we could use it as a pointer to a number longer than 4 bytes.

might turn out to be impossible or not effective but it's worth. look
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 12-6-2019 at 09:12 AM


Quote: Originally posted by MikeDX  
I'm going to have to look into this. it may be possible to abstract divs string type to use floats as I've had an idea about var length since string is a pointer we could use it as a pointer to a number longer than 4 bytes.

might turn out to be impossible or not effective but it's worth. look

Mike, don't waste time on solutions that don't work, the current expression analyzer only works with INT (even strings are INT in DIV), adding floating-point support requires the complete rewriting of the whole analyzer, the parser and other things about the compiler since it's a different data type, you need to add type control, semantics, code generator, runtime type checking and conversions (compiled code and equivalent code to be interpreted in the VM), it's a lot of work to more than what you imagine to make it work as all the compilers that support this feature.

[Edited on 12-6-2019 by CicTec]
View user's profile View All Posts By User

  Go To Top

Powered by XMB
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 18]