Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Resource conservation

Author
Message
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 12th Mar 2008 02:35
Does anyone know if image number can be reused without deletion first. For example, if I were to use number 1 for an image and then make a call to load another image using the same number, does the system drop the old image from memory and load the new one? Or do I need to do a dbDeleteImage to take the old one out of memory?

Lilith, Night Butterfly
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Mar 2008 13:10
Quote: "...image number can be reused without deletion first..."

I wouldn't do that. Better delete it to avoid unnecessary risks.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Mar 2008 23:39
Agreed.... What's a DELETE? I mean... I wrote a class for images that basically...here's sample code snip - typed free hand though...


Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Mar 2008 00:32
Quote: "Agreed.... What's a DELETE? I mean... I wrote a class for images that basically...here's sample code snip - typed free hand though...
+ Code Snippet

void JGC_IMAGE:elete(void){
if(dbImageExist(this->ID)){
dbDeleteImage(this->ID);
};
};

JGC_IMAGE::LoadImageGDK(char *p_szFilename){
this->Delete();
if(dbFileExist(p_szFilename)){
dbLoadImage(p_szFilename);
};
};"


That's basically what I did with my bitmap class. However, I didn't use the 'this' pointer since I didn't see where that would be necessary, albeit maybe prudent. AAR, in working on building a sprite class, at least for my immediate purposes, I was pairing a sprite object with an image object in a derived class of the bitmap class. One of the things that needs to be a part of the sprite class is to check for its existence before calling on any db* function with the number. It should also check for the existence of its related image. I also considered making an image a member object of the sprite class for convenience. Things were starting to get deep at this point and probably very convoluted to the point of my possibly losing track of whether an image number was valid or not and the actions to take if it weren't. And that might have led to some CPU consuming checking and reloading, etc. I was basically trying to figure out the best way of doing things without wasted code

Jeeze. After typing all that I just thought of a way to handle it that might be a bit less involved.

Lilith, Night Butterfly
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Mar 2008 01:17
FYI - I Use the "this" specifier because (not religiously but I try) in a big code block you can tell if a variable is locallay declared or part of the class itself if you make a habit of it. It doesn't impact code - this a readability thing. The only time THIS is 100% necessary is to get the address of the CLASS your code belongs... after that - its eye candy.

Like: MyClass *MyTempPointerToMyClass = this;

What I do to solve your issue is basically I have a IMAGE class, and a global IMAGE ARRAY. That's ONLY so I have a list of them if I ever need it. I don't waste CPU searching through it.

I Have an easy solution for you sprite exists thing too... I mean, I personally have a sprite class... it has an ID field, upon creation, an ID is generated. I also can override the default constructor with an alternate WHERE I SPECIFY the ID (not autogenerated) Then I have a Sprite Class with NO SPRITE no ID!

This trick also allows me to recycle a SpriteID for "temp use" and responsibly create, use, delete (from GDK) I can either keep the class and dictate that class uses ID=56 (and thats it... even if its making and deleting its GDK Sprite 56 constantly.

The other beni to this arrangment is you could set the ID to Zero when you are through. Now you can check that. you can iterate through the array and do stuff on NON-ID=0 sprites.

What I DONT recommend is adding IF DBSPRITEEXIST or DBIMAGEEXIST before every command... that would 1 take alot of effort to code - 2 drain CPU cycles 3 if your stilling about it see reason 1

I guess I don't have YOUR solution the more I think about ...these are just ideas - I'd need to know what you're doing to understand maybe WHY your method has to happen this way or that because personally I haven't run into this exacrt need... and for the record dbBitmaps are slower than images - though I don't know why you call your base class BITMAP... could be an arbitrary name... if not - I don't see how Bitmap, image, and sprite should be remotely connected - as they are different, different and so different.... However I do See why you might make a class that has those three in one - because your THING is made of those base components.

Hope my rambling has been interesting at least

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Mar 2008 04:53
Well, I just spend the last two hours typing a longish dissertation and when I went to post it the system told me I wasn't logged in and I lost the whole thing. So, tomorrow I'll spend some time following up and hope I can remember what the devil I said.

Lilith, Night Butterfly
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Mar 2008 05:21
When I'm doing those - and now you will too - I open my favorite text editor, and then paste it....because that has happened to me more times than I can count.....then I get lazy ...stop doiong that ...then I get bit again for another go round LOL

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Mar 2008 06:58
Quote: "When I'm doing those - and now you will too - I open my favorite text editor, and then paste it....because that has happened to me more times than I can count.....then I get lazy ...stop doiong that ...then I get bit again for another go round LOL"


That's exactly what I did. Considering my day job is administering a largish email system I've had to give my users the same advice after they call and ask if there's a way to recover text when the program crashes. Thank goodness the next version will have autosave.

AAR, my newly revised (and hopefully logical and understandable) text is in the next post.

Lilith, Night Butterfly
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Mar 2008 07:05
Warning, more rambling.

Let me see if I can put this in perspective and in a linear fashion.

One of the first things I did when I began my program was to instantiate my objects at the global level. This is a preferrence of mine because to do otherwise obligates me to create some functions at some of the higher call levels where I have to pass objects to the functions. To me that forces me to take more of a procedural than an object oriented approach. That does, of course, depend on how complex your code needs to get. I believe in letting the objects do most of the work, mostly for keeping code ncapsulated and reuseable rather than having odd functions running around my code in an assortment of files.

I'll use a bitmap class as my example but it still extends to sprite and image classes and other classes as yet unwritten.

My bitmap class encapsulates a static integer called nextBitmapNumber that's set to '1' when initialized. When a bitmap object is instantiated I assign nextBitmapNumber to the bitmapNumber member of my class and increment nextBitmapNumber for use with the next bitmap I may instantiate. The natural inclination is to follow the assignment with a call to dbCreateBitmap () to have the GDK create one in it's system. But if I do this with an object that's declared globally it generates an exception because the DarkGDK () function hasn't initialized the GDK yet. Even worse, with the workarounds I've had to use, I found
that I can't declare a global GDK object with a dbDelete*() call in the destructor without exiting with an abend.

So my bitmap class is filled with lots of tests to make sure that it exists in GDK before using it. Otherwise it creates one. To me this is something of a waste. And with the intertwining of sprites and images it gets more complex when the sprite needs to know if the image object is valid or just assumes it is. I was having to declare the objects globally and then making calls to make sure that GDK had created its counterpart. If I fail to make that call then the image number that a sprite may expect to be valid may not be.

That said, I've worked out the following approach. My main.cpp looks something like this (give or take)



I then write the DarkGame class. The objects that I otherwise would have declared as global are now member objects of that class. This makes them available to all the methods that are part of the DarkGame class, essentially giving them a global presence and eliminting the need to pass them down to higher level functions. Since the object is declared inside the DarkGDK () function all the GDK functionality is established before the member objects are instantiated. The constructor for the class also takes care of all the other things that are otherwise set, like display settings, sync and a few other things indiginous to the game. Invoking the Run() function is like running main() in a regular program. I wish I knew how to create a template of this arrangement.

So if I declare a bitmap, sprite or image object under this approach I can afford to call dbCreateBitmap () (or dbSprite(), etc.) against the number I've assigned to it without having to anticipate an error. This pretty much eliminates the need to check for the validity unless I provide an avenue to delete it other than the destructor.

Okay, now on to the bitmap w/ sprite thingy. The current phase of my development involves laying out some roadway and I found hand editing was not only tedious but also rife with errors. I also discovered that some of my concepts required rethinking so early work at hand editing required a lot of reworking. So I've developed a program for creating the level layouts visually. I believe in letting the object do the grunt work. It helps cut down on the procedural code, breaks the code down into functional units and keeps the code available for reuse without having to keep track of a bunch of functions scattered about my development environment.

My map editor involves a grid on which I click start and end points for a road segment. To do this I created a Grid class that I derived from my Bitmap class. It includes the functionality to draw a grassy background, a grid with clickable intersections, drawing the road segments, deleting road segments, saving the layout to a binary file and loading a saved file. I thought I was finished but realized that I really needed to include the starting point for the vehicles, their startup delay and relative speed. For this I figure on doing a drag and drop. So I need sprites for the players vehicle and the other vehicles declared as objects in the Grid class along with matching images. I might also add some buildings, trees, some road blocks and the powerups. AAR, for each sprite I would need to specify the image and would need to rely on the image being valid. Under my old programming model I would have had some complications but under the new one I think I've eliminated some of the concerns I had.

I also had considered making a sprite class with an embedded image or even trying a special class that inherited from a sprite and an image class. But I dislike multiple inheritance.

Lilith, Night Butterfly
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Mar 2008 07:43
One other thing I meant to add to my approach (now that I'm off topic anyway. Hey! I started the thread! )

AAR, because I want to used named objects with of of my db calls I've include a public member overload like

operator int (){return bitmapNumber;}

That allows me to, for example, copy one bitmap (Background) to another (BackSave) by doing something like...

Background.CopyTo(BackSave);

This might present some problems down the line, but at the moment it seems to fit in with the GDK's way of doing things.

Lilith, Night Butterfly
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Mar 2008 13:38
Quote: "But I dislike multiple inheritance.
"
- I love them. I can take 1,2,3,4,5 base things, and wrap them into a controller that simplfies and establishes rules for my arbitrary creations

Have you looked at the OOP Wrapper I made? I think you should examine the source and pick up some ideas and throw out the rest:

(New Release coming soon but that one is quite functional... needs Sparky and DarkPhysics... though you can scrub out DarkPhysics.. next release it will be a compiler defined switch)

http://code.google.com/p/darkgdkoop/

Regarding your Bitmap.copy thing.. Look at jgc_image.cpp and jgc_pixelgrid.cpp (and their header files of course )

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Mar 2008 16:02
I've downloaded the wrapper but really haven't had time to look at the code. I generally need to print things out and look at them in my free moments, when I'm away from my computers, when I'm studying things.

The problem I find with multiple inheritance is that I have to be very careful with declaring virtual functions, something I'm not comfortable with. I think C# has it right not allowing multiple inheritance except from interfaces.

And I don't have Dark Physics (yet.) I think it's more useful for 3D games, which I haven' gotten up the ambitiousness to tackle (yet.)

Lilith, Night Butterfly
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Mar 2008 21:41
Vitual Functions? Hmm... In this context I don't have an issue yet... I mean, I use virtual functions sometimes, but I often "OVERRIDE" and still Inherit to ADD to the functionality already there...

And frankly, I like the ability to stuff three classes into a wrapper for organization, and when I do, I make the code that handles the three classes separate, and if I WANT I can drill into the baby classes from outside by keeping them public.

For example - A Bad Guy, might have 2 or three objects, etc. All the GDK type stuff wrapped in my game base classes... like OBJECT SPRITE whatever, I don't really EXTEND. I just make them public just in case... I would design such a class with things relative to the BADGUY

BADGUY.Forward
BADGUY.ForwardFast
BADGUY.Die
BADGUY.HealthAdd
BadGuy.HealthRemove

etc... so I haven't run into the issues your saying to much - and that's not to say they are not valid.

I'm thankful that C++ allows you to do either the method you describe about C# AND the way I find nice to use as well.

I guess that's something I'm learning to like in C++ is that ... Well.. It's just REALLY FLEXIBLE! I like that. This is why I like FREEPASCAL also.

C# is fine. But I simply ENJOY C++ so much more... I actually have fun fighting with it... because when I get it right - it ROCKS - when I goof - its not acceptable. I kinda like how its less forgiving - very EXACT in nature, and how its closer to CPU and simply put - FAST AS HELL (Like freepascal).

Lilith - I Hope you get into 3d - because its really fun also. I mean - lots of people are like WHEN I FINISH MY GAME.... I Think I have as much fun making it as playing and when its finished...its finished. There is so much to see and learn while building LOL...

Case and Point... My first few goes with Dark Physics... I WAS playing SOCCER with TANKS! How bizarre is that? I would "kick" them over trees (Camera was my Super hulk soccer-tank kicker) and I would watch the tanks land and bounce off tree etc....

But I digressed WAY off topic...sorry LOL

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 15th Mar 2008 00:57
Actually I finished the game over two decades ago. Unfortunately it was in Z80 assembler code and the written for the ColecoVision. By the time I finished the game the market had dried up. So now I'm rewriting it but with come modern sensibilities and no four sprite limit.

I originally learned C because it was recommended as something that could help me earn a job position. C++ came along because it was there but it took me years to apply myself to the learning process. It also took a long time for me to see the benefits of OOP. I prefer C++ due mostly to my familiarity with it but C# has been beneficial when it comes to having access to the .NET framework. Otherwise I couldn't write program that send email alerts inside of a day.

Lilith, Night Butterfly
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 15th Mar 2008 01:17
WOW - Cool... and I was not to "open armed" about C++ originally.. C, yeah, C++ ... Nope.. Then I got into FreePascal because its better from a GEAR HEAD'S Stat's pouint of view... execution time, compile speed, better for parallel processing than C++ could ever be without a huge LAYER on it... (boils down to some very nerdy reasons why) BUT - let's face it... its more mainstream.. so I finally hunkered down when I wanted TGC stuff to be FASTER and I DarkGDK came out.

Login to post a reply

Server time is: 2024-11-17 08:55:26
Your offset time is: 2024-11-17 08:55:26