Redefine BMAP pointer

Posted By: exile

Redefine BMAP pointer - 01/17/14 16:43

Hey guys,

So what I am trying to do is essentially redefine a BMAP* object. Example;

Code:
BMAP* picture;

function changePicture()
{
var change = 0;
while(1)
 {
  if(picture==NULL)
  {
    wait(1)
  }
  if(change == 1)
  {
    picture = "image_a.bmp";
  }
  else
  {
  picture = "image_b.bmp"
  }
    wait(1)
  }
}


Essentially I need to change the contents of the BMAP pointer without changing the pointer itself since the function I am using this in conjunction with is pan_setbutton. Anyone know of a good/clever way of doing this
Posted By: Ch40zzC0d3r

Re: Redefine BMAP pointer - 01/17/14 17:47

Why not declare 3 BMAPS and only set the data?
Code:
typedef struct BMAP {
	C_LINK	link;
	long 	width,height; // original size of the bitmap
	long	bytespp;	// original bytes per pixel (1..4)
	void	*ptr;		// internal use
	byte	*pixels;	// ptr to palettized, 565, 4444, 888 or 8888 coded original image
	long	flags;      // see BMPF_... above
	void	*d3dtex;	// 	LPDIRECT3DTEXTURE9 (usually a different format than the original image)
	float	u1,v1,u2,v2; // texture pixel bounds
	long	u,v;		// cutout start size
	long	refcount;	// for implicitely created bmaps
	long	finalwidth,finalheight,finalbytespp;
	long	pitch,finalpitch;
	long	miplevels;
	long	finalformat;
	void	*finalbits;	// bitmap content when locked, otherwise NULL
} BMAP;



If you dont know what I mean, Im talking about
Code:
void	*d3dtex;



You could also simply change ALL classmembers with memcpy. Would be the easiest one without changing the pointer:
Code:
memcpy((void*)oldBmapPtr, (void*)newBmapContent, sizeof(BMAP));

Posted By: WretchedSid

Re: Redefine BMAP pointer - 01/17/14 18:17

Holy fuck, don't!
Don't copy data around that you don't own, you will break stuff badly! Just alone fucking up the linked list is bad, but copying opaque pointer around... Why are you advising people to do stupid shit like that?!

@exile:
There is no way to get the same pointer or just exchanging the content. You can use the bitmap operations to make a copy of the bitmap, but this is going to be slow. What you should do is make your code able to deal with the changing pointer, eg. you could implement a notification system that allows potential listeners to listen for changes.
Posted By: Ch40zzC0d3r

Re: Redefine BMAP pointer - 01/17/14 18:43

Why shouldnt it work?? o.0
I dont really get your point frown
Posted By: Uhrwerk

Re: Redefine BMAP pointer - 01/17/14 19:32

What's unclear about "fucking up the linked list" ? Besides that you copy several pointers you have no idea of if and how long they are valid.
Posted By: Ch40zzC0d3r

Re: Redefine BMAP pointer - 01/17/14 20:46

Well I dont really know how the intern clockwork of this engine works, so I thought this could work^^
But if the engine keeps all elements in an array and changes some pointers and mine not then yeah, it would be fucked up xD
Posted By: Uhrwerk

Re: Redefine BMAP pointer - 01/17/14 21:09

You should have a look at the C_LINK structure. That's a linked list. Not an array. As a general rule you should stick to JustSid's advice: "Don't copy data around that you don't own".

exile, maybe you can desribe the thing you want to do in more detail. How does using pan_setbutton make it necessary to change the bitmap but not the pointer?
Posted By: WretchedSid

Re: Redefine BMAP pointer - 01/18/14 00:32

Originally Posted By: Ch40zzC0d3r
Well I dont really know how the intern clockwork of this engine works, so I thought this could work^^
But if the engine keeps all elements in an array and changes some pointers and mine not then yeah, it would be fucked up xD

Of course the engine is going to do something with its pointers. And the point is that you don't know it! Even worse, what the engine does can change any time with an update. It's a black box that you don't know or own and that you have no power over, stay the fuck away from it.

Like... What the fuck?! What if I take one of your frameworks and randomly change internal stuff? Does it just work when I say that I don't know how your stuff work so I figured it might just work?!
Posted By: exile

Re: Redefine BMAP pointer - 01/20/14 19:23

Well, I have a panel object which is a "Map vote" panel. This panel consists of 4 elements, the panel background image, the map name, the gametype name, and a small map image. Players can vote on the map and gametype they wish to play before the match starts. Anyway, I have the structure setup in a way where the server scans a 'Maps' folder and looks for a mapConfig.xml file which contains the map file to load, map name, map description, small map image, and large map image. The server sends the information to the client machines in a multidimensional array where the client machines use the information which was sent to them. The elements for the voting panels are set based on the information they get from the server. So I need to be able to change what the BMAP pointer points to in order to change the map image. I "COULD" use the map images as their own panel and just change the BMAP but I would prefer to keep everything in a self contained object. I think I am going to make my own custom panel structure rather than rely on gamestudios pre-defined objects. draw_quad FTW lol.
Posted By: Uhrwerk

Re: Redefine BMAP pointer - 01/20/14 20:03

From my point of view exchaning the pointer would be the easiest solution and quite frankly I still do not understand why you want to avoid that.

Have you thought about copying the image data over to the bitmap with bmap_blit? http://www.conitec.net/beta/bmap_blit.htm
Posted By: exile

Re: Redefine BMAP pointer - 01/20/14 20:26

Because that would mean I have to create a new pointer for each BMAP. i want to be able to support user generated maps along with "official" maps. Since the list of maps and gametypes is populated into a list and that list may vary from person to person, there isnt any way I can think of which would allow that.
Posted By: Uhrwerk

Re: Redefine BMAP pointer - 01/20/14 21:05

I still don't get it. Copying the stuff over with bmap_blit does not change the bitmaps addresses. It just changes the bitmaps contents. That is exactly what you asked for in the first place:
Originally Posted By: exile
Essentially I need to change the contents of the BMAP pointer without changing the pointer itself
Sorry if I am mistaking you somehow...
Posted By: DLively

Re: Redefine BMAP pointer - 01/20/14 22:06

I dont want to be the guy in the middle who gets hit with the 'trace', but I think Ch40zzC0d3r was only trying to help - I dont believe he was trying to hurt anyone. He is only learning, just as we all are in many new areas - His advice was only an input, not a command.

Anyway, Couldn't you set it up into a function that holds all the bmaps in one section, the maps in another and so on? I realize you are trying to avoid this for what I would assume to be professional and learning reasons, however...

function calculate_map_settings(){

vote_pan.bmap = vote_panel;
if(vote_ran == 1){vote_panel = <thismap.bmp>;}

}

I stopped before I went to far ahead. I would never want to insult you with this primitive stuff you already know - but this is what I would do.

Cheers.
© 2024 lite-C Forums