CLEO Help draw_texture

CLEO related
Status
Not open for further replies.

ItsRobinson

Active member
Joined
Nov 16, 2017
Messages
105
Reaction score
20
PHP:
:drawIcon
0470: 4@ = $PLAYER_ACTOR
format 20@ "cleo\HDhud\resources\%d.png" 4@
0B71: render 6@ = load_texture_from_file 20@
0@ = 1578
1@ = 91
0@ += 6
0B73: render draw_texture 6@ pos 0@ 1@ size 75 75 rotation 0 color 0xFFFFFFFF
return

I've got a gosub to the function above, which should get the players weapon in hand and then grab the weapons icon from the resources folder (inside the resources the folder I have the weapons ID's as the name, hence the %d.png) 

The issue with this is that it'll work for a few seconds and then my FPS drops from around 150 to 70 and then a few seconds later from 70 to 15. I'm not exactly sure why that's happening but I know it's something to do with this because I deleted the gosub and that didn't happen.

I've been converting my lua script into a cleo and my lua script works like this:
PHP:
function drawWeapon(posX, posY, sizeX, sizeY, wep)
	weptext = renderLoadTextureFromFile(string.format("moonloader/resource/icons/%d.png", wep))
	renderDrawTexture(weptext, posX, posY, sizeX, sizeY, 0, 0xFFFFFFFF)
	renderReleaseTexture(weptext)
end


So I've tried in the CLEO releasing the texture after drawing it, but that then just doesn't make the icon appear.

So I'm stuck for what to do, any ideas?
 

DavidRO99

Active member
Joined
Nov 5, 2017
Messages
60
Reaction score
8
You are probably calling this in a loop, loading the texture in memory every drawing frame, as you can probably think this is bad, pretty bad, this is going to quickly fill memory up with copies of the texture.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
you could also wrap loading textures and getting specific ones using functions, if you take a look at the source of the mod from link below you'll see I tried to solve the same problem:
http://ugbase.eu/Thread-CLEO-shootingIndicator

[shcode=cpp]:LoadPictures
0@ += 4//to avoid using 0 as the index value (EDIT: my weapon file names started with 1 instead of 0 so that's why it was here)
alloc 31@ 64
for 29@ = 1 to 14
0AD3: 31@ "CLEO\weapon_images\%d.png" 29@
   if 0AAB:   file_exists 31@
   then
   0B71: render 30@ = load_texture_from_file 31@
   0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1
   0@ += 4
   else
   0AF8: samp add_message_to_chat ".png file not found" color -1
   end
end
free 31@
0AB2: ret 0

:GetPicPtr
1@ *= 4
005A: 0@ += 1@
0A8D: 31@ = read_memory 0@ size 4 virtual_protect 1
0AB2: ret 1 31@[/shcode]

and just like Opcode.eXe mentioned:
0AB1: @LoadPictures 1 0@ was called once (it's necessary to use "alloc 0@ <number_of_files_multipled_by_4>" before loading them)
then pointer to specific picture can be retrieved using:
0AB1: @GetPicPtr 2 array 0@ weapon_id 1@  _ret 2@
and 2@ can be used in:
0B73: render draw_texture 2@ pos 0@ 1@ size 75 75 rotation 0 color 0xFFFFFFFF
 

ItsRobinson

Active member
Joined
Nov 16, 2017
Messages
105
Reaction score
20
monday said:
you could also wrap loading textures and getting specific ones using functions, if you take a look at the source of the mod from link below you'll see I tried to solve the same problem:
http://ugbase.eu/Thread-CLEO-shootingIndicator

[shcode=cpp]:LoadPictures
0@ += 4//to avoid using 0 as the index value (EDIT: my weapon file names started with 1 instead of 0 so that's why it was here)
alloc 31@ 64
for 29@ = 1 to 14
0AD3: 31@ "CLEO\weapon_images\%d.png" 29@
   if 0AAB:   file_exists 31@
   then
   0B71: render 30@ = load_texture_from_file 31@
   0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1
   0@ += 4
   else
   0AF8: samp add_message_to_chat ".png file not found" color -1
   end
end
free 31@
0AB2: ret 0

:GetPicPtr
1@ *= 4
005A: 0@ += 1@
0A8D: 31@ = read_memory 0@ size 4 virtual_protect 1
0AB2: ret 1 31@[/shcode]

and just like Opcode.eXe mentioned:
0AB1: @LoadPictures 1 0@ was called once (it's necessary to use "alloc 0@ <number_of_files_multipled_by_4>" before loading them)
then pointer to specific picture can be retrieved using:
0AB1: @GetPicPtr 2 array 0@ weapon_id 1@  _ret 2@
and 2@ can be used in:
0B73: render draw_texture 2@ pos 0@ 1@ size 75 75 rotation 0 color 0xFFFFFFFF

I've tried interpolate your way of doing it into my program. It completely broke everything aha. (everything flickers and I can't log in)


PHP:
alloc 20@ 100

0AB1: @LoadPictures 1 20@
This is straight after the check to see if SAMP is available ^ (outside of the loop)

PHP:
//icon
0470: 4@ = $PLAYER_ACTOR
0AB1: @GetPicPtr 2 20@ 4@ _ret 5@
0@ = 1578
1@ = 91
0@ += 6
0B73: render draw_texture 5@ pos 0@ 1@ size 75 75 rotation 0 color 0xFFFFFFFF
This is inside of my loop ^ (I'm assuming this is where it's breaking)

PHP:
:LoadPictures
0@ += 4//to avoid using 0 as the index value
alloc 31@ 64
for 29@ = 1 to 46
0AD3: 31@ "CLEO\HDhud\resources\%d.png" 29@
    if 0AAB:   file_exists 31@
    then
    0B71: render 30@ = load_texture_from_file 31@
    0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1 
    0@ += 4
    end
end
free 31@
0AB2: ret 0

:GetPicPtr 
1@ *= 4
005A: 0@ += 1@
0A8D: 31@ = read_memory 0@ size 4 virtual_protect 1
0AB2: ret 1 31@
And then these are the snippets I pinched from your cleo.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
assuming that you're using all images uncluding "0.png" you should remove:
0@ += 4

and edit:
for 29@ = 0 to 46 // 0 instead of 1

also, there are 47 images all together, each taking 4 bytes (integer), so you'll need to allocate at least 188 bytes
 

ItsRobinson

Active member
Joined
Nov 16, 2017
Messages
105
Reaction score
20
monday said:
assuming that you're using all images uncluding "0.png" you should remove:
0@ += 4

and edit:
for 29@ = 0 to 46 // 0 instead of 1

also, there are 47 images all together, each taking 4 bytes (integer), so you'll need to allocate at least 188 bytes

Yeah it was the amount of memory I was allocating that was breaking everything :)

I got it semi-working now, it's loading the textures, but it's displaying the wrong ones.

http://prntscr.com/l08eh3

I'm assuming it's something to do with what you mentioned about the "0@ += 4"


PHP:
:LoadPictures
0@ += 4 //If I delete this line the files actually work.
alloc 31@ 64
for 29@ = 1 to 46
0AD3: 31@ "CLEO\HDhud\resources\%d.png" 29@
    if 0AAB:   file_exists 31@
    then
    0B71: render 30@ = load_texture_from_file 31@
    0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1 
    0@ += 4 //If I delete this line the only image that loads is the last one (46.png)
    end
end
free 31@
0AB2: ret 0

PHP:
:GetPicPtr 
1@ *= 4 //Then you get the result in the picture, ID 24 showing picture 7.png rather than 24.png
005A: 0@ += 1@
0A8D: 31@ = read_memory 0@ size 4 virtual_protect 1
0AB2: ret 1 31@

(read comments in code)

Not really sure how to fix this because it seems like it's just grabbing random numbers, because knuckle dusters are showing for fist, which is only a 1 multiplier and then 24 is removing 17, not really sure what the fuck is going on aha


With my code like this:
PHP:
//icon
0470: 4@ = $PLAYER_ACTOR
0AB1: @GetPicPtr 2 20@ 4@ _ret 5@
0@ = 1578
1@ = 91
0@ += 6
0B73: render draw_texture 5@ pos 0@ 1@ size 75 75 rotation 0 color 0xFFFFFFFF

// Inside loop ^

:LoadPictures
alloc 31@ 64
for 29@ = 1 to 46
0AD3: 31@ "CLEO\HDhud\resources\%d.png" 29@
    if 0AAB:   file_exists 31@
    then
    0B71: render 30@ = load_texture_from_file 31@
    0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1 
    0@ += 4
    end
end
free 31@
0AB2: ret 0

:GetPicPtr 
1@ *= 4
005A: 0@ += 1@
0A8D: 31@ = read_memory 0@ size 4 virtual_protect 1
0AB2: ret 1 31@

The result in-game is this:
[video=youtube]https://www.youtube.com/watch?v=F4JrEQR_0bQ[/video]
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
if anyone wanted to implement the same then the issue was about 3 files missing in this cool coloured wepon pack:
http://camil1999mods.blogspot.com/2013/10/relsa-hd-weapon-icons.html

missing IDs are 19,20,21 so it can be fixed in 2 ways:
1. By creating transparent/empty file and using it when other files can't be found (see the code below)
2. By implementing bitmap/bytemap to indicate which weapon IDs are missing and when it's their turn to be displayed just don't display them

here's the essential part, slightly modified to make it work with any weapon ids

PHP:
/*
to be called once:
alloc 0@ 200
call @LoadPictures 1 0@  

to be called when drawing:
0AB1: @GetPicPtr 2 array 0@ weapon_id 24  _ret 2@
0B73: render draw_texture 2@ pos 500 250 size 75 75 rotation 0 color 0xFFFFFFFF 
*/

:LoadPictures
alloc 31@ 64
for 29@ = 0 to 46
0AD3: 31@ "CLEO\weapon_images_\%d.png" 29@
   if 0AAB:   file_exists 31@
   then
   0B71: render 30@ = load_texture_from_file 31@
   0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1
   else
   chatmsg "%s file was not found..." -1 31@
   0AD3: 31@ "CLEO\weapon_images\SOME_SMALL_TRANSPARENT_IMAGE.png"
   0B71: render 30@ = load_texture_from_file 31@
   0A8C: write_memory 0@ size 4 value 30@ virtual_protect 1
   end
   0@ += 4
end
free 31@
0AB2: ret 0

:GetPicPtr 
1@ *= 4
005A: 0@ += 1@
0A8D: 31@ = read_memory 0@ size 4 virtual_protect 1
0AB2: ret 1 31@
 
Status
Not open for further replies.
Top