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 / C++ OO Wrapper

Author
Message
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Sep 2007 23:08
Since the last release of the lightweight wrapper I provided way back in 2005 I've been working almost exclusively on DBPro specific extensions. Now, if there is enough interest, I'm thinking of picking up where I left off with the wrapper and extending it to cover all of the DSDK interfaces.

If I do this, the library will be freely available at a source-code level under the BSD license.

Register your interest here

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 17th Sep 2007 14:43
IamM I think you have the right approach. Seems every one around here has reinvented this time and time again. Yet know one has release such a thing. Personally with all the brilliant minds around here I thing a group effort is in order. Maybe that just me. Either way If you release something i'll certainly check it out.
Red Ocktober
20
Years of Service
User Offline
Joined: 6th Dec 2003
Location:
Posted: 17th Sep 2007 17:16
i'm too far down the road with my OO engine to consider a rewrite...

besides, i don't understand the need for a OOP wrapper...

just code it with classes, using an OO approach...

--Mike
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 17th Sep 2007 18:24
I guess that depends on the definition of wrapper. I took all the DB functions and created classes based on them I call this a wrapper.
Red Ocktober
20
Years of Service
User Offline
Joined: 6th Dec 2003
Location:
Posted: 17th Sep 2007 20:44
whatever your definition of a wrapper may be, what would be the point of doing that... i mean, why take ALL the DB functions and wrap them into a classes... without any purpose, except to wrap em into classes...


--Mike
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 17th Sep 2007 22:18
Well If i put all the function in a class I can access them as members? Again maybe are definition are different here?

dbShowObject ( object1 );
dbHideObject ( object1 );

Object.show();
Object.Hide();

This way an object is an object and input is an input and camera is a camera etc...

I guess I see your point Mike, You could always just make a class Load. that uses all the functions DB has to offer load it and be done with it. But for me this just makes coding easy were I know I can use an object class in the same convention is most engines out there. Especial .. Now i know you hate this.. But especial for intelesence. But seriously Mike to each their own eh?
kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 17th Sep 2007 22:42
@unitech: That's what I was going to mention. It makes just a lot easier to read and write code. There are even things that makes it better.

As an example:
DGDK.NET has a class called dgdkSound that has all sound methods. On my LightEngine plugin, they are divided two 3 specialized classes: LightSound, Light3DSound and LightRecordSound.

Light3DSound has methods to position it, while the others don't. LightRecordSound has the ability to record and save, the others don't.

This may sound silly, but how many people would try to position a sound that was not loaded as 3D sound? They all share the same ID pool. It's easier to track things by name, but not by IDs. (And other classes share this same features).

Last, but not least, intelisense is a great helper, and that makes all the difference when choosing "to be or not to be" OOP.

Thiago
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 17th Sep 2007 23:36
I think I understand what Red Ocktober is on about, I've gone down the route of creating classes for things I need to do and embedding the GDK stuff inside it. (I'm using VB.net over C++ but the principle is the same)

I've got no plans to OO everything, And instead of using something someone else has written to be useable in a generic way, I've now got custom classes that do exactly what I need them to do in a way that fits into the whole project.

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 18th Sep 2007 00:28
I know about your work Jas.

I can tell with a complete bag of experience that building up an all-purpose wrapper for DGDK is a lot of work, I can't remember how many nights of sleep I lost with LightEngine, because I was so concentrated that I couldn't turn off the pc...

But there are good things about it:
1 - Anybody can use my work.
2 - I can make plenty of games without modifying the main classes, just inherit from them and add specific methods/properties.

One thing I noticed about DGDK(C++) users is that everybody wants to do it's own and not to share the final results, so everybody's reinventing the wheel everytime.

I'm not telling it isn't worth it, at least it was for me, as I spend many hours reading about the Framework guidelines and now I see myself as a better programmer, but there were plenty of people that told they gave up doing it because of LightEngine, for the sake of speeding up development of their game.

Well, that's just my two cents about it. Hope nobody feels offended, I respect everyone's thoughts.

Best regards,
Thiago
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Sep 2007 00:37
Quote: "I've got no plans to OO everything"

Absolutely.

I don't see any point in wrapping standard maths functions or DBPro window stuff (position, title, on/off etc) into objects, but anything that has ID's such as objects, images, lights etc, then yes.

@kBessa,
If you check my work with DBPro plug-ins, you'll see that I try my hardest to make things as safe and easy to use as possible. I also make sure that there is no impact on DBPro from those plug-ins - you pay for what you use, and no more. I intend to maintain that philosophy if I go ahead with this library.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 02:03
(My turn)

I saw this post when it was just IanM's First "any Interest?" and decided not to say anything because - well - Topic asked one thing - "You interested?" and I wasn't. NOT because IanM writes bad stuff - quite the contraire - but far be it from me to say YEAH DUDE GO FOR IT - when I woulnd't use it anyway other than to study.

I agree with Red - Why Bother?!? It CAN eat clock cycles up if its not done right or "over done".

I agree with IanM - Only for stuff with ID's. Yuppers - Cuz you can eliminate certain mundane things - and develop the OOP stuff with "Dynamic" in mind so you can concentrate on WHAT you're doing versus HOW. (does that read like I meant it? hmm...)

I agree with kBessa - Intellisense - helps in a pinch - saves tons of looking "around" to see if you got the right object to do said whatever or search the command (because it knows what its a part of .. so category is usually good enough to find what ya want)

I agree with jasuk70 on having "my own bag of tricks".

Rewriting the wheel doesn't seem to make sense - lost time yadda yadda... but for me - writing a library to help me do what I want - is more enjoyable than studying someone else's "framework" and all the nuances of thier stuff. By making my own - if it doesn't work - its my fault - PLUS chances are good I can fix it pretty darn quick because I'm intimate with every little "int i;" and "void*" in the thing. All the surprises - are my own making. Plus I have full control AND liability for misused clock cycles. Game going to slow? Let me switch it up this or that I know could be tighter etc.

Also - last note of caution - some of those "little" stubs you might put in a class as a funtion - like - (psuedo)


Are wonderful - but if unchecked - you could have things like this called TONS of times - and that couple extra "commands" each call - multiplied - can boil down to "WTF" I wrote good code man - ITS SLOWER than I WANT!

This is another reason I like "having my own wheel".

Now in a business app - where a couple seconds - or even minutes gets the job done - is acceptable - I'll go with using every tool out there to get it together. I'll code it as correct as time/money allow... but for my own game - where I'm making my own little digital world? I don't mind. I actually like the fact that while the game is playing I pretty much know everything that is going on and can bask in its glory - (or not so much glory all the same).

I also don't wish to offend - glad we can discuss this stuff - afterall - this is a niche "hobby"... for me anyway.

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 14:41 Edited at: 18th Sep 2007 14:42
I think the wrapper Idea would be great for any "newbies" for sure. But as far as writing something most of use c++ gurus would use, it would have to be a well thought out group effort. So many of us have our own signature paradigms that would make us to stubborn to use another's. For examples I would not settle for a less efficient ID handler. Also I built a 3rd person class in my camera class that I could reuse from game to game extending the used of point followto and other function DB had. These are things I can live with out, but would totally be up to seeing a better way.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 14:46
Quote: "I can't remember how many nights of sleep I lost with LightEngine, because I was so concentrated that I couldn't turn off the pc"


Some of my best code is written in the wee hours when everyone is sleeping - and not a creature is stirring... except for my mouse...


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Sep 2007 15:32
Ok, don't take this the wrong way, but I would never write code as per your example - that's not taking advantage of C++ at all.

That kind of code should be written once, no more, for all 'entities' that can be rotated around 3 axis'.

In addition, my earlier released code was explained in an accompanying document that described the reasons behind the code, so that people studying both that and the code could learn from it and hopefully understand the trade-offs I was making - I intend to continue any further development in the same vein. Hopefully, even if people don't use it themselves, it'll help them design their own.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Red Ocktober
20
Years of Service
User Offline
Joined: 6th Dec 2003
Location:
Posted: 18th Sep 2007 15:59
@ jason...
well said j...

also... i'm usually up at 5 am coding myself... when most of the world is in the throws of that lucid dream sequence


@ unitech...
yeah... a noob (like me ) might benefit from looking at the code and how it's structured... i agree... no doubt...

also... regarding the id handlers... a simple id factory in the core class (i have it as a method in my Game class) can consist of nothing more than incrementing a private variable whenever a new id is required... the base class for all objects in my framework (the GameObject class) includes a variable called objNumber, so that every new object of a class derived from GameObject can reference it... in the constructor for each new Gameobject derived class, i make a call to Game->GetNextObject(); which provides the new instance of the class with the next available object number, and stores it for later use...

since this is done automatically, you never have to worry about overlapping or duplicate object numbers causing problems...

i also do the same thing for meshes (mesh numbers), images (image numbers), memblocks, effects, anything that requires the use of a unique number identifier...

this way the entire number thing becomes transparent after the class is written, and i never have to worry about it again...


@ everyone...
yeah... this is a good discussion... lots of good input from all over...

OO development is more than just coding... it's your whole approach toward a project... the way you visualize the entire thing in your mind... since everyone envisions things differently, unless you are working as part of a team, following someone elses visualization and logic may not be the best idea... in short, this is one case where a few different wheels is not necessarily a bad thing...

me, for example, i do things a lil off the cuff... since i'm naturally lazy, i have my declarations and implementation all in one file (the .h file)... bad practice, but it works for me...

also... i use a single event handler (generated by the Game class which raises a universal update event in order to provide each object (class) with the ability to auto update itself...

also, i don't use a linked list structure for my framework, which, i think, would be the best way to whip up an OO framework... i may adopt something like this later...

my general approach is to keep everything simple... to keep my classes as small and as single purpose as possible... write it, test it, make sure that one lil piece of functionality works, then build up upon it, deriving new related classes from already validated ones...

that's my only reluctance to employing huge, all encompassing wrappers...

--Mike
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 17:55
@IanM -

Quote: "Ok, don't take this the wrong way, but I would never write code as per your example - that's not taking advantage of C++ at all."


Me either! I was explaining how that sort of thing eats clock cycles. HoweverI think there is more wisdom in your statement than you let out - which is why I also am always listening to all of you!

Quote: "That kind of code should be written once, no more, for all 'entities' that can be rotated around 3 axis'."


I hear ya but I don't EXACTLY know what you're implying. If you are saying you should have already checked the "existance" once like my example - versus having each member check again... I agree. If you mean something else - do share

Quote: "In addition, my earlier released code was explained in an accompanying document that described the reasons behind the code, so that people studying both that and the code could learn from it and hopefully understand the trade-offs I was making"
that is so over the top - above and beyond what is normal - and I for one think that is so AWESOME that you do that.

Quote: "I intend to continue any further development in the same vein. Hopefully, even if people don't use it themselves, it'll help them design their own."


I'm gonna need to check this stuff out Could be enlightning!


I've been coding long enough where I see good and bad design when I understand the "jist" of what is available - and the problem. I'm half-decent at coming up with manageable efficient solutions. Example: I made the fastest web server I've seen yet that can run on 32bit - linux or win32. Like my DarkGDK stuff - My first run through might not be the fastest - but I try to make things - SAFE and with as little redundancy as possible - and then I can trim the fat as needed or when I'm in a mood to do that sort of thing - looking to shave a few clocks here and there.

I'm the first to admit in my wrapper so far - there are places where if I could do an inline function - it's be faster - (I don't THINK...or haven't figured out yet) How to make a class member execute inline - by defition of OOP (same Code - one place - used from everywhere) I think that won't work and I need to make some regular inline functions that do said task with param's so the "tidbits" I don't want to waste clock on a jump/jsr (jump subroutine when compiled to machine code) or double dereferenced pointer operation (Fast - but even this takes more CPU clocks - the actual machine code for this operation tends to be in the teens (not milliseconds - cycles at whatever giga hertz your pc is at...I know I know - but these add up.)

IanM - I don't know how long you've been coding but you're obviously not a newbie and keep the "strong statements" coming because I personally prefer someone who thinks they have a better idea putting it on the table out there for all to see - even in my face - over those who snicker and move on without saying anything gloating or whatever.




@Mike - Thanx for the Well Said thing and back at ya - this is a design approach thing all day! That is why IanM (guessing) is so ready to share stuff he sees as wrong... not because the pseudo code I tossed up there is wrong - it would work - but its not ideal and bad practices - (like was my point) might seem "good enough" and maybe they are in many cases... but when that "mistake" and others like it are the norm - your application speed (and management of your code often) will suffer.

Now - this is one of those deals where I think GAME Programming is MORE intense than business programming usually. In business - a developer who codes for living will hear: "Dont overdesign it - get it done" "They didn't pay for all those bells and whistles" "Just get it to work - you have an hour from start to finish" "We don't care about the details - just get the data from here to there - they didn't pay for datascrubbing"

This is often followed by "How come there are bugs?" "Didn't you test everything?" (In that hour you gave me? yeah right.)

but in gaming - I think many of us agree - that the reason we came to DarkGDK was speed - and writing sloppy clock cycle wasting code defeats the purpose! Speed = Faster FPS but it also means More things you have going on in your game. Display should be the slowest thing - and you're program should always be waiting for the display to finish - not the display waiting for your code to process so much it lowers frames. This is one of my goals - let's see if I can pull it off in Iron Infantry - in DarkGDK....

(I love this thread)

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 19:25
Quote: ""Didn't you test everything?""
- another reason IanM s idea is good. I don't care how good you are, you can predict it all. From the prev thread on OO coding, and as Mike said "regarding the id handlers." that is a perfect example why its smart to share something so similar. This way you don't have to learn a "game specific" limitation the hard way. For example I wrote a light limiter for a max of 8 lights 0-7.Also the light and camera has to start on 0. Objects must start at 1, or things could fail (i.e.) sparkies collision if you plan to use it. There also is problems when using ID's in high number stated in the docs. Now i dont know about most of you but this could be all publicly shared knowledge and help any one out there. Although if your a solo type I can see why you would like doing it all your self. Personally I'm with Mike I don't mind learning and doing it all my self it has a its glory to it. But For the company I work for it could have saved them a month of time spent writing designing and debugging wile developing the game.
Red Ocktober
20
Years of Service
User Offline
Joined: 6th Dec 2003
Location:
Posted: 18th Sep 2007 20:08 Edited at: 18th Sep 2007 20:10
Quote: "There also is problems when using ID's in high number stated in the docs. "


yeah... that's a good point uni...

i'm anticipating this possibly becoming an issue down the line, but so far, since all my objects haven't generated a DB object number higher than 8, and the camera numbers, image numbers, and mesh numbers, are also correspondingly low...

since i have no logic in place to account for deleting objects or images, nor do i plan to implement such logic (right now), therefore, the used numbers will be wasted, and any new stuff created will generated higher numbers...

in a real game, this may become problematic for the very reason you mentioned... when i get a lil farther down the line i'm going to stress test this, loading up a whole array of objects and different images...

the explosion resulting from the crash could be deafening

--Mike
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 20:21 Edited at: 18th Sep 2007 20:22
Ya it took about 3 months before it cause a problem for me. But at the time I was doing all id sequentially. The only re-using I'm working on is the vector ID's Since they are not allocated in the same way int float ect, I need to issue the memory back when finished with them. My largest number is under 1000 now.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 20:30
Don't laugh - this function runs fast and allows the "Fast" increment way as well as the "But I need a number up high for temp reasons" or whatever:

(Go ahead - pick it apart - I know what ya will say hehehe - but works pretty good for me!) Note: Each Object Stores it's own LASTIDUSED number - and manages it separately. This "Factory" is selfcontained so its usuable from the "wrapper" stuff I'm writing as well as for standalone - like subroutines that might do a bunch of things on various objects - but toss the results when done - hence not wasting unused numbers... note the "Need Temp Numbers" thing I quotes above as example.


I think enum would be better - but this works until I try my first c based enum. (I usually don't like them cuz I like to know exactly what is what)

Da Factory Homies - With Wrap Around at 65535



Note the speed comes from using the last used id trick which is the same as your incremented value pretty much. cnObject just a constant to mean OBJECT versus mesh, bitmap etc.


I thought about IanM's idea - making this part of the base class but I kinda want it separate for tricky stuff where class isn't applicable. Like the SplitIamge thing I'm doing - is in my IMAGEDL (Image List) class but it loads a bitmap directly with dbLoadBitmap - etc - and doesn't use the bitmap class at all because its not getting stored for later - I load - I copy - I delete... so the iGetNewID function works for me. I'm sure there is a better way - but its works filawless and is fast when used correctly (So not starting at 1 each time) Also - MY classes have code - say the camera - where they AUTOCREATE the default camera (or light) and then I just use the iGetNewID for additionals. I'm not done yet either - but - there's some code to disect anyway

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 20:43 Edited at: 18th Sep 2007 20:54
Its not bad Jason, I like the the if exists bit. Funny I never though of that. I would have been using a link list if it was not for that std:: error I had. Only gripe with the above is the repetitive code but that could be manageable enough.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 20:54
thanx - as for the reptitive code part (Knew that was coming...if not you IanM surely ) But sometimes - you know - you write the first - tweak it - test it... CNTL-C - PASTE PASTE PASTE and change the DarkGDK calls to their kind - well - didn't take long to do and its fast enough... Repetitive? Yup. Slow? Not with that layout. I'm going to tweak it more so only counts to 7 for camera/light or whatever they stop at - but that is actually way easy with that snippet.

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 20:55 Edited at: 18th Sep 2007 21:02
I here ya..

here is what I have with out a link list.



I think ill add that if exists thing in my code. Would be nifty..
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 21:16
I don't understand what the instance stuff is all about because I'm new to C++ looks interesting and looks very concise... something mine isn't... purposely. (Kinda hoping IanM comes on and shows us both a thing or two eh?)

You know how my code is repetitive? With a LONG Switch/Case statement for each type? In my loop - Thing Type is already decided so that IF isn't called over and over. I traded repetitive/speedy over clean/slower. Your code - is WAY tight and not redundant - and is likely way faster than mine because it doesn't have the db...Exist thing yet - but it will likely have that soon from what you said.

Note - the if light do this else do that happens each loop iteration - that is a "test" which - not a big clock thing - is an unnecessary clock thing... again - If it works etc... but seeing how we are all discussing design I'm just mentioning it.

I also have probably tons of code that can be tightened - if fact I know it - usually I'm more for the MANAGEABLE but for speed sensitive stuff - I do not care if my executable in 10 megs like microsoft word - as long as it runs fast. DiskSpace is cheap - I don't feel the same way about memory and most of all clock cycles - especially where games are concerned.

Unitech - does your project have a name? I don't think I've seen anything from it - I've seen something Jasuk70 is working on - I saw a clip of Red Oktober's - I'd like to see what your doing! (Not to rip - but to admire) RPG? MMO? shooter? 2d Scroller? Level Editor?

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 21:30 Edited at: 18th Sep 2007 21:43
I don't mind showing but its BIG. Called ShipQuest. Its your run of the mill FPS for they Navy. So ya there is a clearance thingy there. LOL the EXE is only 520k the assets are 230 meg. So let me know how you wanna see this? here are some shots..

My second project is a 3rd person Nintendo like game. Still hashing out the completed 3rd cam operation, and I must say its dead on Nintendo's style. Only private inquires on this as I don't need and trouble. I know N gets fussy about that.


Cant find a way to up multiple images so here is a zip.


now about this fast code thing? This is during loading? Sure it may speed up the id allocating during load but not during game play.

ok on to the instance thingy..

think of instance as every instance of the class construction.

in my h file i have this

private:
int m_iNextID[ FACTORY_TYPES ];

static Factory *m_pInstance;

my ID and a static instance.

and in my cpp a pointer to that

Factory *Factory::m_pInstance = 0;

and a return function for it

Factory *Factory::getInstance( void ) {
if( !m_pInstance ) {
m_pInstance = new Factory( );
}
return m_pInstance;
}

So from my code or my object class I coudl do a

m_iID = Factory::getInstance( )->getNextID( TYPE_OBJECT );

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 22:00
@Unitech - DUDE that looks FANTASTIC! (Reminds me of my commercial fishing winter) That looks Really really Cool!

code thing:
Quote: "now about this fast code thing? This is during loading? Sure it may speed up the id allocating during load but not during game play.
"
Might have missed the wave a bit - but it should be decent regardless of if during load or during gameplay. though that big "numbers slow down objects" etc thing is a quandry.


Instance thing:: I see how you're doing it now - thanks for that little run down!

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 18th Sep 2007 22:07 Edited at: 18th Sep 2007 22:08
Thx man, its more about the game play then looks for my though. It is the simple things like shooting lights deletes the light from the lights array, Or my menu handling system, or the bug I caused that became a feature where moving from right to let causes the gun to move from one side of the head to the other.. Loves those bugs...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Sep 2007 22:15
just thought of a dumb idea that would kinda work - deleting things leaves holes right? What about something that ran maybe 5 "iterations" per loop that was like a garbage collector - like an array of 100 (hardcoded or whatever - that each game loop - would check for "unused" ID's and toss them in the "Queue" then as new id's were needed - they would first come from the 100 "Ready to go" list and if exhausted the looping method... and as game played - the queue would be rejunate?!? I kinda like this idea.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Sep 2007 22:35
Y'know, I think that you should stop giving away my secrets

This is from the very first release of the code, separated out into its own header.


NumberResource
Maintains a high-watermark of the last ID allocated (initially 0), and a
stack of freed IDs (initially empty).

When a new item is requested, the value held on top of the stack is popped
and returned. If the stack is empty, the high-watermark is incremented by 1
and it's value is returned.

When an ID is freed, it is pushed onto the stack.


... Although I have another system now that may be better - I just need to benchmark speed and memory usage.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 18th Sep 2007 23:29
Hmm, seems familiar



Though I did mine after kBessa's suggestion and its vb.net

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 19th Sep 2007 05:30 Edited at: 19th Sep 2007 05:31
LOL this just furthers the point in collaboration. Look at all of this redundant madness here. Indeed a smart approach. who needs an effort to create a ID handler, this thread is becoming one ....
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Sep 2007 06:08
Its all IanM's Fault!!



Night Guys - been a VERY good coding day for me. Tomorrow ... I I have to go to my real job... Good Day!

(Oh IanM - I got the image splitter working via dbGetImage for now) First animation test - WOW - so Smooth! DarkGDK rocks!

kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 19th Sep 2007 07:07
Hey, LightEngine's is very similar to IanM's one, but I can't say whether it was inspired by it or not, as MudBug was the one who implemented it.

One thing we did was to make a static IdManager copy in every media type class, so when creating a new instance, you do just something like "this.Id = IdManager.GetNextId();"

The only thing missing in the current release is a "Max ID" verification. Although it has been implemented and will be present on the next version.

@unitech: I didn't start Light and Camera at 0. One thing I done was to create a base class for each one, then inherited to two classes: Camera (that controls the default camera) and AditionalCamera (for cameras 1 to 7). I think is better this way as you can delete aditional cameras, but not the default one. And I think it makes it clearer to know if it is default or aditional. The same applies for Light.

Thiago
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Sep 2007 10:55
Using a single function with an if/switch:
- error-prone maintenance (adding a new counter)
- error-prone usage (passing the right value to get the right counter)
- slower each time you add a new counter

Using an array is a little better - it is less error-prone for maintenance although you still need to remember increase the size of the array and you are changing core code that is used everywhere, and does not slow as you add new counters.

Using a class-specific counter is safest - you can't break another counter as you don't change any existing code, it's fast and safe because there's only one of them in the class.

So sorry Jas, Jason, unitech - kBessa's way is the way to go.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 19th Sep 2007 12:37
To be honest, getting an ID for an item of media isn't on my highest priority list at the moment so I just used something simple Before the original discussion started it was even simpler than it is now .

As with most things it will probably evolve into something a bit less messy, but I think getting the guts of everything else working is a higher priority. I need to get something ready for the Convention, the end of next month

Having some kind of counter class seems a good "Tidy" idea. As I only call my function in one place it should be easy to change later.

Unitech, What you call redundant madness I call a learning experience. If I waited for everyone else to decide how I should do things, I would never learn anything or get anything done. (Hmm that's starting to sound like where I work, far too many people trying to decide how to do things so nothing ends up getting done, There are even meetings here to decide about what should be discussed in the next meeting, I kid you not )

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th Sep 2007 13:07
Quote: "
Using a class-specific counter is safest - you can't break another counter as you don't change any existing code.
"


Separate "source control" for each I buy.

Quote: "
it's fast and safe because there's only one of them in the class.
"


Agreed - but its not "Standalone" as a function. I do think it would make sense to make a little "disconnected" class or one class that was a factory for "Kinds" of ids.

Quote: "
So sorry Jas, Jason, unitech - kBessa's way is the way to go.
"


Not positive about this one. I think this is down at the opinion level now - as to which is THE way to go - I definately think we all have ultimately really hashed this out to a few fundamentally sound ways of doing it. Personally - I contributed a little - and learned a lot - I'll go back - and over time - keep "tailoring" that ID thing a bit at a time to try to get the best of the best of all the things we discussed PLUS make sure its still to my "liking".

Good Morning - got woken up kinda of early - hope I don't sound grumpy - I am - but that's because I have to go to work work

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 19th Sep 2007 14:59 Edited at: 19th Sep 2007 15:53
kBessa, thx for the tip.

jasuk70, I use redundant madness in good humor or a comical sense. And nobody is pointing fingers or show you a road to go down, just offering the smoothest road and suggestions. You don't have to buy a Toyota, but I will tell you it is going to last longer. Simple fact is some of this code has been done for years. Taking advice from Mike, IanM and kBessa (not to leave any one out) is not an act of democracy its an act of learning. I'm not saying to take what they use and work with it, I'm saying think about why they do it the way they do and take example from it. If you can improve from it, by all means do so. My point is simply group efforts is and always will be better to archive a goal. One person simply cant know it all. If you read my posts you will see that is were I'm coming from.


IanM, if you would how is a "Using a class-specific counter" different then the method I use? For "UNDERSTANDING" purposes.. or do you mean using a factory for each is best, rather then a variable for each? Either way I dont have one counter? Because I originally had a factory for each type of class, but didnt see the point in using that..

Personally I think the best method is a link list..This way no reason to increase an array..


and how in the heck did you use " std::stack<int> Free;" with out a linker error? with namespace SDK?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Sep 2007 15:23
Quote: "Agreed - but its not "Standalone" as a function."

I don't understand what you mean by this - I suspect that you've misunderstood what I was saying.

I'm suggesting a single class definition that simply provides numbers as a resource. This is then included as a static member of the class of object or image or bitmap or camera etc.

This means that only one class can access its instance of that number resource (making it safe from uncontrolled access), there are no constants or flags to get right (making it safe from being accidentally accessed such as getting an object id when you meant to get a camera id), and the number resource class itself is simple enough that it will probably be inlined (making it as efficient as accessing a global variable).

This last bit definitely makes it faster than Jas's code with all of its 'if' statements, and also makes it very slightly faster than yours as it avoids offsetting into the array.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 19th Sep 2007 15:39 Edited at: 19th Sep 2007 15:54
Quote: "This means that only one class can access its instance of that number resource (making it safe from uncontrolled access)"
- I would not use any other method then that my self, not sure where I did wrong, but no the less good point to make.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Sep 2007 15:41
@unitech,
Sorry - I was too focused on answering jason and forgot your post

The system I posted code for above is used on a per-class basis. There's one instance for objects, one for cameras, one for images etc

Example:


Because of this, there's no need for using a singleton pattern as the number resource is not a singleton - it's one of many. There's no need for a factory as each instance of the class is only serving one other class. Take a look at how simple my code is compared to yours.

My code uses a stack. The stack itself by default is based on a deque which is implemented as a linked list of multiple nodes. When inserting lots of items at one end or the other, it's faster than a plain linked list purely because it allocates larger sets of nodes instead of the one-at-a-time of the list class.

Quote: "and how in the heck did you use "std::stack<int> Free;" with out a linker error?"

Why would you expect it to not compile & link? The stack is just another object, and I've only given the NumberResource class it's own instance.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 19th Sep 2007 15:45 Edited at: 19th Sep 2007 15:47
I see your point.

When I used std:: I got redefinition errors.

1>display.lib(CGfxC.obj) : error LNK2005: "protected: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Myptr(void)const " (?_Myptr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IBEPBDXZ) already defined in msvcprt.lib(MSVCP80.dll)


for example.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Sep 2007 01:08
That's weird. Maybe this will help ...

I decided to go with this as a tutorial/discussion document, and the first place to start is setting up the initial project - the document is attached in PDF form.

I suggest that you create a new project based upon this document, then copy & import all of your source code into the new project and then see if you have the same problem - I don't. In fact, the following code, although trivial, compiles, links and runs just fine.


Anyway, the real reason for this post is your opinions on the document itself, its style, its content etc. Is it Ok? Is anything missing? Are there other errors? I'd be grateful if you can take the time to check.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 20th Sep 2007 01:30 Edited at: 20th Sep 2007 01:33
Looks really good!!

Need to insert a Prerequisite - "Things you will need to get started. Detailed. I understand if you don't want to do that - but if you nail down some of the details like: DirectX Version ??? Link is: blah blah, Visual Studio blah blah, DarkGDK blah upgrade x.xx released blah blah. Make sure you have x,y,z directories and the following files...

This way when the newbies come on and read and start - you don't get exactly the same question over and over - (ahh... which is a good reason to maybe state - "Before you post your questions in the forums - please be sure of the following: x,y,z"

(You asked us to take a look It's the least I can do. I like the font sizes, the screen shots - the candid - Do this - and this is why - attitude you are pretty much consistant with. It reads nicely.


[edit - read it again] Its so easy reading - I hope you can make the whole thing like that. You should sell it in print if you do that!

unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 20th Sep 2007 14:49 Edited at: 20th Sep 2007 15:48
Hmmm,, well I rememebr there was a bit more to setting up for me, wish I remembered.. For S&G I tried your options based on my set up. I didnt have the quartz ignored and if my runtime is set to anything but multi-thread DLL (/MD) I get errors. For example using your recommendation I get

unresolved external symbol @__security_check_cookie@4

errors. I think this would be an excellent document I may have time to start one from scratch to see if this work for me.





update:: ok add this "Switch Character Set to "Use Multi-Byte Character Set" to general character site. this allows for output in debug trace..

and I cant get passed
1>Linking...
1>libcmt.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invoke_watson@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invalid_parameter@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in LIBCMTD.lib(invarg.obj)

update:: to fix this I used "/FORCE:MULTIPLE" to the end of my compiler line.

I now have STD!!! , oh wait I mean std works... LOL

last update:: I get crashes on dbSetObjectEffect in iosfwd that I never got before. No time at the moment to look in to this.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Sep 2007 15:56
Which version of the GDK are you using? If you are not using the 120307 beta, then you should upgrade.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 20th Sep 2007 16:14
Actually the STD problem is there but only in release mode.

120307 is the version I have.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Sep 2007 19:20
@Jason,
Thanks for the feedback. I'm currently adding a prerequisites section to the document as you suggest.

At the moment, I'm assuming an audience of developers who have used the GDK already a little, and who know a little C++ - I don't want to turn this into a 'teach yourself C++ with GDK' exercise, but I guess I can add a little detail for installing GDK and any other libraries that may be required along the way.

Perhaps I can have a volunteer to document the installation of VC++ Express, the Platform SDK and DirectX, take screenshots etc, so that I can insert the text and maybe adjust the style

... Or maybe just a list of the versions of VC++, Platform SDK & DirectX you have installed?

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 20th Sep 2007 19:32 Edited at: 20th Sep 2007 19:32
He Ian, just wanted to comment the my post was not completely a rant was to help you as well..

take note..

I used "/FORCE:MULTIPLE" to the end of my compiler line.

add this "Switch Character Set to "Use Multi-Byte Character Set" to general character site. this allows for output in debug trace..

Can't hurt..
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Sep 2007 19:55
Can you post the command-line properties for both the Compiler and the linker?

For example, my C++ cmd-line is:


and my linker cmd-line is:


We can work out where the differences are and try to correct your settings from there.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Red Ocktober
20
Years of Service
User Offline
Joined: 6th Dec 2003
Location:
Posted: 20th Sep 2007 21:13
hey uni...

i just took a look at your screenies for the naval project you're working on... verrrrry nice... i like the look...

keep us updated, will ya...

i'm also working on a naval game/sim... still putting the engine together to run it on, but should be adding some game elements soon... i'll post pics as soon as some of the visuals start to fall into place...

good to see another naval game in progress... good luck...

--Mike

Login to post a reply

Server time is: 2024-11-19 16:36:16
Your offset time is: 2024-11-19 16:36:16