SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 03/09/2018, 12:13 AM   #1
Manyula
Huge Clucker
 
Join Date: Jan 2012
Location: Germany
Posts: 282
Reputation: 43
Default progress3D - Create progress bars in 3D space

progress3D.inc



After the 2D textdraw-based version of progress bars, here now comes the 3D version. This library lets you create progress bars in 3D space. It's basically just two overlapping 3D text labels, one being moved slightly to the right to fill in those gaps between the characters. Have fun with it!

Repository



Functions
  • Bar3D:CreateProgressBar3D(Float:x, Float:y, Float:z, layout, fill_color, background_color, Float:max_value, Float:init_value, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = STREAMER_3D_TEXT_LABEL_SD, STREAMER_TAG_AREA areaid = STREAMER_TAG_AREA -1)
    • Creates a 3D progress bar.
  • DestroyProgressBar3D(Bar3D:barid)
    • Destroys a 3D progress bar.
  • GetProgressBar3DValue(Bar3D:barid)
    • Returns the current progress value.
  • SetProgressBar3DValue(Bar3D:barid, Float:value)
    • Updates the value of the specified 3D progress bar.
  • GetProgressBar3DFillColor(Bar3D:barid)
    • Returns the fill color of the specified 3D progress bar.
  • SetProgressBar3DFillColor(Bar3D:barid, fill_color)
    • Updates the fill color of the specified 3D progress bar.
  • GetProgressBar3DBackgroundColor(Bar3D:barid)
    • Returns the background color of the specified 3D progress bar.
  • SetProgressBar3DBackgroundColor(Bar3D:barid, background_color)
    • Updates the background color of the specified 3D progress bar.
  • GetProgressBar3DMaxValue(Bar3D:barid)
    • Returns the maximum value of the specified 3D progress bar.
  • SetProgressBar3DMaxValue(Bar3D:barid, Float:max_value)
    • Updates the maximum value of the specified 3D progress bar.
  • GetProgressBar3DLayout(Bar3D:barid)
    • Returns the layout of the specified 3D progress bar.
  • SetProgressBar3DLayout(Bar3D:barid, layout)
    • Updates the layout of the specified 3D progress bar.
  • IsValidProgressBar3D(Bar3D:barid)
    • Returns true, if the specified 3D progress bar ID is valid and exists.

Changelog

v1.3.1
  • Moved the position parameters x, y, z to the front of Bar3D:CreateProgressBar3D(...)
  • Slightly improved code readability

v1.3
  • Added a new parameter layout with three new bar layout options
    • BAR_3D_LAYOUT_THIN
    • BAR_3D_LAYOUT_NORMAL
    • BAR_3D_LAYOUT_THICK
  • Added GetProgressBar3DLayout(Bar3D:barid) and SetProgressBar3DLayout(Bar3D:barid, layout)

v1.2.1
  • Fixed getter functions (forgot to add "_:" to the returned value)

v1.2
  • Added the parameter Float:max_value to Bar3D:CreateProgressBar3D(...)
  • Added GetProgressBar3DMaxValue(Bar3D:barid)
  • Added SetProgressBar3DMaxValue(Bar3D:barid, Float:max_value)
  • Updated the testing script

v1.1
  • Code optimizations
  • Internal check if value ranges from 0 to 100.

v1.0
  • Initial release
__________________

Last edited by Manyula; 05/10/2018 at 04:46 PM.
Manyula is offline   Reply With Quote
Old 03/09/2018, 01:21 AM   #2
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,420
Reputation: 1240
Default Re: progress3D - Create progress bars in 3D space

Code:
static Bar3D:Bars3D[MAX_3D_BARS][BAR_3D_DATA],
       Text3D:Bars1[MAX_3D_BARS],
       Text3D:Bars2[MAX_3D_BARS];

new Iterator:Bars3D_Index<MAX_3D_BARS>,
    Iterator:Bars1_Index<MAX_3D_BARS>,
    Iterator:Bars2_Index<MAX_3D_BARS>;
Create one iterator, one variable and one enum instead of this disaster.
Pottus is offline   Reply With Quote
Old 03/09/2018, 05:29 AM   #3
Alteh
Little Clucker
 
Alteh's Avatar
 
Join Date: Aug 2018
Posts: 31
Reputation: 3
Default Re: progress3D - Create progress bars in 3D space

It looks interesting but it improves the code please.

Good release
Alteh is offline   Reply With Quote
Old 03/09/2018, 08:06 AM   #4
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,952
Reputation: 1548
Default Re: progress3D - Create progress bars in 3D space

Nice one! I've written some constructive feedback below:

To add to what Pottus said: consolodate all the data related to a bar into a single enumerated array so there's no need for multiple iterators. Storing data in multiple places like this can lead to difficult and non-obvious bugs related to data being out of sync. If you modify one but forget to modify another, problems will arise.

PHP Code:
enum BAR_3D_DATA {
    
fillColor,
    
backgroundColor,
    
Float:barValue,
    
Text3D:Bar1,
    
Text3D:Bar2
}

static 
Bar3D:Bars3D[MAX_3D_BARS][BAR_3D_DATA],

new 
Iterator:Bars3D_Index<MAX_3D_BARS>; 
Libraries should also generally never use `print` directly, either put it behind a "DEBUG" constant that the user can disable or remove it entirely. There's only one print here but it's not necessary, the call-site already knows that the bar creation failed because the function returns `INVALID_3D_BAR` - it's up to the user to check and handle that case, which is far more realistic than monitoring the log file for a very specific phrase.

Another thing I noticed was a lot of copy-paste code, bar1/bar2 could be globally allocated as `static const` to remove the need to allocate on the stack. And the code that calculates and manipulates the label text could be delegated to a separate function because currently it's copied into three places, if you had to fix a bug you'd have to fix it three times, which increases the chances of typos introducing more bugs!

Aside from that, the code is pretty good. There might be some string manipulation optimisations to be done but it's probably unnecessary. Good work!
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 03/09/2018, 08:42 AM   #5
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,129
Reputation: 3170
Default Re: progress3D - Create progress bars in 3D space

Contrary to what others said, I like multiple variables over enums sometimes, but they're right that the three iterators are pointless. Also, you might want to start using YSI_Data\y_iterate as the correct path.

But I like the include concept.
Y_Less is offline   Reply With Quote
Old 03/09/2018, 11:54 AM   #6
Kemula
Big Clucker
 
Join Date: Sep 2012
Posts: 101
Reputation: 1
Default Re: progress3D - Create progress bars in 3D space

I'm taking this!

Nice work.
Kemula is offline   Reply With Quote
Old 03/09/2018, 01:16 PM   #7
Manyula
Huge Clucker
 
Join Date: Jan 2012
Location: Germany
Posts: 282
Reputation: 43
Default Re: progress3D - Create progress bars in 3D space

First of all, thank you for the constructive feedback!

Quote:
Originally Posted by [HLF]Southclaw View Post
Another thing I noticed was a lot of copy-paste code, bar1/bar2 could be globally allocated as `static const` to remove the need to allocate on the stack. And the code that calculates and manipulates the label text could be delegated to a separate function because currently it's copied into three places, if you had to fix a bug you'd have to fix it three times, which increases the chances of typos introducing more bugs!

Aside from that, the code is pretty good. There might be some string manipulation optimisations to be done but it's probably unnecessary. Good work!
In the first pass, I usually prioritize functional over optimized code - the latter is something I bother about in the second pass, so delegating the progress calculation to a separate function is definitely something I'll do, thanks!

About the stack allocation: So, you're saying that I should just do this?
PHP Code:
static const bar1[] = "IIIIIIIIIIIIIIIIIIIIIIIII",
             
bar2[] = " IIIIIIIIIIIIIIIIIIIIIIIII"
__________________
Manyula is offline   Reply With Quote
Old 03/09/2018, 02:31 PM   #8
KinderClans
Gangsta
 
KinderClans's Avatar
 
Join Date: May 2018
Location: Italy
Posts: 639
Reputation: 36
Default Re: progress3D - Create progress bars in 3D space

So if for example i have a timer of 20 seconds, how i can set the progress bar to fill completely in 20 seconds?
__________________
LSS RP Discord: https://discord.gg/M9c9PjN

https://is.gd/cheap_vps

Extremely cheap VPS from 5$ monthly (SSD Cached) - Features:

512MB Memory | 500GB Disk Space | 1 TB Transfer | 2 Core Processor | 1 IP Address

Against everyone and everything.

I'll have two number 9s, a number 9 large, a number 6 with extra dip, a number 7, two number 45s, one with cheese... and a large soda.
KinderClans is offline   Reply With Quote
Old 03/09/2018, 02:47 PM   #9
Manyula
Huge Clucker
 
Join Date: Jan 2012
Location: Germany
Posts: 282
Reputation: 43
Default Re: progress3D - Create progress bars in 3D space

For now, the progress is calculated in percent, so 0.0 is the minimum and 100.0 is the maximum value.
So, if 20 seconds are 100%, then 1 seconds equals 100/20 = 5%. So, each second, you would have to increase the value by 5.0.

I realize, this might be a bit inconvenient to use. I might add "min_value" and "max_value" parameters and let the function do the calculations for you in the near future.
__________________
Manyula is offline   Reply With Quote
Old 03/09/2018, 03:14 PM   #10
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 2,003
Reputation: 473
Default Re: progress3D - Create progress bars in 3D space

Nice release.

Last edited by SyS; 03/09/2018 at 03:45 PM.
SyS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Progress Bars v2 GoldenLion Scripting Help 0 14/09/2016 01:03 PM
Textdraw and Progress Bars prioritizing MoemenWalid Scripting Help 6 08/05/2016 07:57 PM
Moving Progress Bars eеe Scripting Help 2 05/01/2012 04:17 AM
Progress Bars Creation CrucixTM Help Archive 0 15/12/2010 07:29 AM


All times are GMT. The time now is 03:37 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.