Sunday, September 28, 2003

Back at Uni - not much progress. Currently on a bit of a hold, though most features are documented and there are several todo lists saying what I need to progress in.

I'll probably start more work again as soon as pressure from various other projects starts :)

Tuesday, September 16, 2003

I've done half of my documenting for the Lower Engine but no commenting.

Monday, September 15, 2003

Finished Documenting and Commenting my UpperMap section of my code.

Sunday, September 14, 2003

Currently have a bit of a cold, documentation continues at its rather slow pace.
It should be called documentation / optimization / simplifying the code which can only be a good thing.
It should only take one more shove and I'll have finished the UpperMap documentation.
The next tricky thing to document is the screen, all the rest of the code should be quite straight forward.
In a couple of weeks I head back to Uni too, I'm unsure if this will speed things up or slow them down.
Slow for at least freshers week I'm sure.

Thursday, September 11, 2003

More documenting / tutorializing globe class.
If I pushed myself I could do a large amount of this in a much shorter time.
Though as I go I'm simplfy the code and creating a to do list to make it even cleaner to work with.

Tuesday, September 09, 2003

Enders Saga Book 4 finished. Its waning for me ... I think I'll take a break from this series , amybe I'll read the Golden Fool book. I've already read the first Robin Hobb is a great writer but this series is still being written so it will probably be ages before I get to read the last book :(
I can hardly remember the first
Still going through the Upper Layer of my Engine.
Found some suprisingly redundant code and created a small todo list of what needes fixing up.
Yesterday documenting the upper engine ... its going okay though I'm still taking it quite slow and I haven't really been reading any technical texts.

Friday, September 05, 2003

Wrote a chunk of a C# tutorial I'm thinking of doing.
It starts very basic and simple. My writing style tends to be ramlby as per usual but each part is thoroughly covered.
If I get to putting something of the screen, then I think it will be worth something to some body and I'll review what I've written and submit it where I can.

Preferably I'd like to get as far as a small tile engine.

Thursday, September 04, 2003

Writing pretty design docs/tech docs/notes; I want to have a firmer plan before continuing. This could go on for a while each day I'm only doing a little at the moment.

Tuesday, September 02, 2003

Mainly typing up notes and making sure I know how everything fits together so far.

Monday, September 01, 2003

Doxygen is alot like JavaDoc, infact it seems you can switch to JavaDoc style syntax. Seeing as I'm using someones elses tools to create the docs though - I'll leave it as it is.


//! A pure virtual member.
/*!
\sa testMe()
\param c1 the first argument.
\param c2 the second argument.
*/
virtual void testMeToo(char c1,char c2) = 0;


The first line is the brief description.
The next line between /*! and !*\, is where the detailed description goes.
The \sa, is See Also, I think
Then \param "name of the parameter", allows indivual commenting on the parameters.

Its pretty straight forward - the last thing I need to lock it down is to find where the Assert and debug commands are in C#.
Doxygen is in there and working well.
I'm pleased.
I've also starting writing a tutorial / documentation of my Engine class or generally using DirectX3D with C# for tile games. If it turns out okay I'll send it into GameDev.

Its going slow at the moment - I am enjoying Final Fantasy Tactics: Advance though :)

Friday, August 29, 2003

Now KingTools seem to be in there too, which provide a handy little shortcut for using Doxygens Commenting system.
My programs, or at least the latest incarnatins work with 2003 .net.
I'm unintalling Visual Studio .net, I just hope it doesn't break my current installation.
Upgrading to .net 2003.
In some ways its good that MS has become involved in our Uni.
Currently its a good Uni that teaches strong Computer Science i.e. a lot of mathmatics no vendor specific crap.
There's also a large Unix lab and thats what our OS course is based on, I don't think increasing MS involvement will harm this, infact I think they're merely looking to do a little brain farming.

Wednesday, August 27, 2003

Trying to document the Engine class, actually the run up to the Engine class - but the names of the projects are not ordered and trawling through them is all a bit random. I have so many different projects where I may have been proving something, or trying to do something and failing, or doing something as a step to be carried on by other projects. They need to be sorted and named.

Which brings me to my Uberbase, if I created this these things probably wouldn't be a problem.

Monday, August 25, 2003

http://www.idevgames.com/content/download.php?id=72
Wonder is this might fit the bill.
My Time classes are working well. They need a bit of polishing, a bit of extending but basically they're good and working. The documentation is good too, it could do with some examples but apart from that I'm happy.

The question comes what to do next?
I have part of a design doc on another system and scattered round various books.
The engine is documented on s number of random sheets of paper and notebooks but that needs to be brought togetther.
Currently everything is still simple and reasonable modular.

I think intergrating the Time and Engine into a new solution would be a good idea. Then get a globe that has more than one block. Give each block a detailed map with a number of textures. Then see how it handles the scrolling across it. Then adjust the globe and maps sizes to see how roboust it is.

So I need new tiles 32X32.
I'm not going to spruce up the Texturer and this point, all new tiles will be hardcoded in. If I see a good way to automate this I will make note of it.
Then create some setup function that will get everything moving, and allow me to experiment.
I still need to learn how to use Doxygen effectively with C# or C' internal commenting system.
I have been on the look out for tiles but I've ben having a little trouble.
I'll have a look now, then I might start arranging my documenation and start consolidating some of the Engine stuff.

Saturday, August 23, 2003

Yesterday I wrote my some of the more tricky bits of my time code and then started to document / explain it. That way I won't forget how it works for now i'm just writing a xhtml file that steps me through the code.

Friday, August 22, 2003

Tools I'm Using


C# through the VS.net IDE
DirectX 9.0 api
Notepad for design documents and the like written in xhtml
Doxygen for all my commenting needs
A blog from blogger to record my progress

Graphics and music are just stand bys until I get to a stage where I need to start making these look a little more professional.

References Used


Books

Software Engineering For Computer Games - see book recommendations for more detail info.
Special Effects Game Programming with Direct X, despite the name this is a resonable introduction to Direct3D and I've found it quite useful.

Websites

MSDN Library DirectX - offical DirectX docs
BuffPortion - Handy information about creating a full screen DirectX app using C#
Enginuity - GameDev tutorial about creating a 3D engine from scratch, using C++
Extreme .Net Forums - slow forum about game design using the .Net framework

2D Engine using 3D API info

2D Rendering in DirectX 8 - GameDev article uses C# and an early version of DirectX but still very handy.
... I had a number of these links but it seems I've failed to save them all.
To use handy Doxygen plugin tools I need to updgrade to VS.net 2003 bah.

Thursday, August 21, 2003

Book Recommendations



Book name hyperlinks goto Amazon where you can check the reviews and whatnot.
Also note that I'm affiliated! All the links open in new windows.

I read a lot of books these are the books that I consider having something special or having a direct effect on my game programming techincal ability, the books that I want recommend / force other people to read.

Game Programming





Tricks of the Windows Game Programming Guru, this book is recommended a lot and it is good but there are drawbacks. Its not up to date, even in the second edition you'll be using DirectX one or two versions old. It only covers 2D games using the no longer supported DirectDraw library. Despite these drawbacks its full of good information, about graphics, sound, ai, networking, optimization ... its a game programming opus magnum and if you are new to game programming it is a must buy. Note that it is assumed you are able to program C\C++.

Software Engineering and Computer Games:..., garish front cover, title that mentions MFC - this sounds like an awful book. It is not awful though its a very useful book - if your looking for a book about how to program and design a game or its engine this book has the lessons. How to add a physics engine easily into a 3D world. Important OOP patterns for use in game programming. There is a lot of good stuff in here. The author uses his own frame work to take you through it and you will learn a lot. The frame work that the author creates is a little too general for most games but with the implementation details from 'Tricks of the Windows Game Programming Guru' (or the web or your own knowledge) you should have no trouble applying the lessons taught here.


Recommended Tech Reading





The Code Book: The Secret History of..., this is a very easy to read book. It introduces cryptography in a very accessible way and gives the interesting history behind its use. Even though this book is for the casual reader, it gives plenty of technical information that could be applied to your programs. It also has a very good reference section.



A New Kind of Science, hotly debated book but very interesting. It talks about creating complexity from simple rules. This has direct interest to me and i'm sure other games producers. He demonstrates much of this through cellular autonama, but the theory is not restricted to them. Despite the misgivings of experts in several fields this touches, I believe this does have some worth and brings something new to the table. For some more info there's a rather interesting article here.



Computer Graphics: Principles and Practice, this is the computer graphics text. I have no doubt it is on the shelf of the Maya, 3DSMax, Lightwave Designers shelves. It is quite technical, you need to know your maths and your computer notation but its the major reference book.



Fuzzy Thinking: The New Science of Fuzzy Logic, a great and very easy introduction in to the world of fuzzy thinking. It has a great number of applications in games. Fuzzy logic is covered a little in Tricks of the Windows Game Programming Guru but this book makes it far clearer and simple. It will help you design programs that appear more intelligent.



Godel, Escher, Bach: An Eternal Golden Braid, very much a must have book. It revolves around consciousness and how this might be produced in a computer. It mixes fields from music, maths, art, zen, ancient Greece ... it is very readable and enjoyable.


Creativity / Inspirational



The Art of Looking Sideways, much like 'Godel, Escher, Bach: An Eternal Golden Braid', this book covers a lot of topics, infact it even mentions 'Godel, Escher, Bach: An Eternal Golden Braid' a number of times. It is in no way technical but it is an indescribably wonderful book that pulls things from everywhere.


Recommended General Reading



While these may not directly give insight to computer game programming, it is beneficial to broaden your mind to other ways of thinking.



Dance, Dance, Dance, or anything by Haruki Murakami. His books feel like poems and leave you in awe.


The Unbearable Lightness of Being, a book that will effect you, has some of the dreamness quality of Murakami but greater emotional effect. How could a game ever produce these kind of feelings?


This entry is used as a reference page.
2003 (c) Daniel Schuller.




Tuesday, August 19, 2003

Got some of the Time stuff done.
My progress has been stalling slightly, attributed slightly to playing lionheart and lack of visual feedback from my project.

Friday, August 15, 2003

In my c# windows programming book I'm now on the Timer and Time. Yay! This is hat i'm about to start messing with in my game os that came together nicely.
I finally finished font, I skimmed the last part of it. It tells you how do a lot of stuff. Stuff I won't remember and stuff that I'm quite unlikely to use, but if I ever need to I know its there.

Thursday, August 14, 2003

I've gathered all my Time knowledge together in a new Solution File (the little of it there is)

Currently I need to document the tile engine but for this I need a book that gos over the commenting niggles of C#, its seems there might be something clever there. If not, them I'm going to have to work out Doxygen.

Also loosing momentum a bit. So I'm going to focus a tiny bit more on my reading and learning.

Monday, August 11, 2003

Among other things I'm currently writing out my design doc in digital ink.
Using xhtml, clean and simple. I can spruce it up later with cascading stlye sheets.
Page about links in xhtml, this will be useful later.

I've fixed my code so it works now, more than one block will require a little bit of tinkering. But for now I think I've finished this section and I'll move on to time.
I need to read some articles about it and do some console apps until I have a framework that I'm happy will be easy to work.
So close to the end stage of this part of the engine.
It crashes ... but at least it is now crashing for the right reasons.

Sunday, August 10, 2003

Some of the functions have assumptions I'm not meeting.
I wish I could remember where the assert command was hiding.

Its also so hot, even now its overcast my curtains are shut and I can feel a shean of sweat.

Wednesday, August 06, 2003

Scrolling up now wraps for globes greater than one block ( i assume not tested)

The TextureMachine is currently inelegant and needs to be refactored in later.

Tuesday, August 05, 2003

And thats the intialisation code all done!
Lack of current progress has to be blamed on Britains unsual heat wave and in no way my irreproachable self discipline.

Currently doing some of the globe classes intialisation functions, which went wrong and have now become a bit more generalized and useful.

Saturday, August 02, 2003

I've started to fix up the globe class.
Once this is done I have my base.
The magic numbers in the wrapping code, need to become a little more magically so they work correctly on the Right + Down axis.

next I will do time probably using a console output.
Then I really should test my base for extensibility and make sure its really solid.

Thursday, July 31, 2003

I think I have the scrolling down now ... hopefully.
Gah, there's a bug.
I don't know if its in the Wrapping or the scrolling parts.
I'm now suspecting the wrapping, after spending a lot of time going through exactly what the scrolling does.

Hmm there seem to be problems with the wrapping to :(

Tuesday, July 29, 2003

Well scrolling is in.
I don't really have a full understanding of why it works but it does.
Hopefully it works as I planned and I should didn't foresee that it needed to be implemented in the way it became implemeneted.
I intend to do a web based tutorial anyway where I'll clear all this up.

The only problem now is the actually scrolling is notically bumpy where before I just suspected.
As I suspected pixel by pixel scrolling turned out to be much more tricky than I had imagined.

It currently works if you are travelling up the screen, all the other axis are currently not working.
I'll come bakc to this later and fill out the details.

Friday, July 25, 2003

. . . Cleaned up my code a little. Bits really need moving, but I'm okay with it. I'm ready to move on to pixel by pixel movement and then getting an arbitary globe set up.

I drawn out my current stuff in UML.

I can come back to this stage and work it again.

Also started working on a small texture editing program, but I've done very little with it so far.
Cleaned up the code a little yesterday.
Did some work on Fonts with my Windows Programming book.
Read another chpater of Software design book today.

Wednesday, July 23, 2003

Wrapping works, you can now walk right around my world.
I suspect in some directions it may not be smooth (jumps a few tiles)
I believe this is because it is true for Right-directional wrapping. I'm not sure why
I'll have to have a closer check once I get a more detailed map.

So now what, I could do a number of things from here.
I think first I'll finish off the wrapping so it can handle any number of blocks.
Before that I'm going to clean up the code again. After that thats the end of this section!

Then animating, pixelXpixel movement or time.
Time seems the most likely but I think pixel by pixel movement will be independant of time anyhoo.

Anyway I'm happy with what I've got so far.

Tuesday, July 22, 2003

Wrapping is very close to completely working. All that needs doing is changing which block is the current "active" block
But it wraps round the corners fine at the moment, but if you walk more than a block + one screen size worth in any direction it will fail.
The block needs to be swapped out.
This shouldn't be too hard. Though it requires building up another datastructure
My wrapping algorimth was fundementally wrong, its on the right track now, I hope :)

Monday, July 21, 2003

Got my wrapping partially working but it doesn't work holistically.
Gah. It needs some sever debugging, so far I suspect its having problems plotting the Prime rectrangle though I'm not sure why, I'll have to hook some outputs.

Sunday, July 20, 2003

Software Engineering and Computer Games
By Rudy Rucker

Read a couple of chapters of this today.
Looked at my code long enough to realize to do wrapping properly I need to define some extra structures.
Once I get that done I can strip down some of the classes, make them inherit from common sources.

Saturday, July 19, 2003

It now amazingly works.
Though I hacked it in rather roughly just changed it then kept compiling till all the errors had been dealt with.
Now to slowly get back to doing the wrapping code.
Tracked down the problem I was having.
Having not programming in a no-pointer language for a while it took my a while to find it and make the mistake in the first place.

I had my rectangles filling themselves from the same area of the same block.
They were therefore both pointing to tiles in the source block.
Unfortunaly in the tile data structure I placed a translation matrix :(
So each time the copy rect was called they changed the translation matrix.
So they were plotted in the same place every time.
This is unlikely to happen in the game but it could if I messed enough with the setup, its lucky I caught it now.

Shouldn't be too hard to fix now I've found it!
The wrapping code, to make my world Donut like is proving a major headache.
Though I've just finished the chpater on the mouse.
I think I may start another ebook in tandum, as the Windows one tends to drag.

Tuesday, July 15, 2003

I cleaned up as much of the code as I could.
Some of the public stuff needs hiding away a bit better.

I added code that stops overrunning the block data structure.
It also outputs to the console the amount of overlap.
Next I'll make it wrap back on itself. Once it is over 50% in a new block that will become the active block.
I'm only using one block at the moment, though my code should be general.
I fine that I have to include global coordinates ranging over all blocks also.
This is currently all in a little rough, but working.

Monday, July 14, 2003

Movements is in.
Finishing this 'stepping-stone', this has been the largest block and I had to clean errors from early blocks too!
Currently movement has no bounds checking, and I think the code could be cleaner.

But that ones done. The next step has to be a kind of cleansing and then adding in the wrapping code and introducing a global co-ordinate system.
Then I can move to a new chapter of stepping stones, that will probably be concerned with timing.
Finshed the last bit of my console program. It worked correctly. Its not effiecent as it could be, but its reasonably clear and correct.
I've hacked it into my old code and after chasing down a bug with the screen constructor not intiliazing the transform matrixes correctly it now all seems to work :o

So i need to clean up the code one again.
Then I need to introduce movement.
I really need to look up Assert implmentation in C# too. I know they're somewhere around.

Saturday, July 12, 2003

It seems the code I'd written so far was not correct.
The rectangle stuff is slightly more involved than it seemed.
I've corrected a lot of other stuff.

Currently I'm working on a small console program trying to get my algorimth working in that. Then I fit it into my main code.

Friday, July 11, 2003

I wrote a few proof of concepts text window programs as I went along to clear things up for me.
The C#/.NET ide, makes this wonderfuly easy.
I've got some basic block structures in place.
These are the local maps, loaded as needed.
The user see a portion of the block.
The possiblity may occur where the user sees 4 different blocks at once on the screen.
Therefore I may pull sub rectangles from each block to create the entire user view.

This is done now and hopefully working. It proved rather challenging.
using modulus with blocks indexing from zero, confused me for a while but its not too bad now.
The next stage is getting a bit of movement.
Currently I'm not concerning myself with pixel by pixel movement but I believe I'll do it by writing outside the rectangle and allowing it to clip it.

First block by block movement. I don't know if I'll do any more tonight.
Still on the mouse chapter of my windows book, though quite near the end. The chapters are mammoth and there are nearly 20 of them :(

Thursday, July 10, 2003

I've done another two tasks. I've cleaned up my code a little. Created a rudimentary texture manager that I'll probably rewrite.
First I created a bit of a tile class and then got some setup and blit like loops up.
So I can fill the screen area perfectly with tiles.

I need to define a block (which will be larger than the screen area) and then use this to scroll through the map.
This means overwritting the keyboard codes.

I msy decide how to do all this :)

Tuesday, July 08, 2003

I done my little set of tasks.
Its all very simple.
I found jupming in and trying to build something big, was not working for me at all.
My program can load D3D into a window or into fullscreen - for some reason the sprites are not shown in full screen. I suspect I might see them if I scrolled my screen up with the controls. I'll leave this until I've done some big tiling.

First program puts a tile at the correct place in the top left hand corner of the window. Textured from a 256x256 bitmap taking out a 32x32 chunk, to coloured the tile grass.
Then the second program used the same vertex buffer but changed the texture and put that next to it.

So I now have a nice piece of grass followed by a gray tile that looks nothing like a road.

Unfortunately to do this I have to lock and unlock the vertex buffer. I hear this is expensive but unless I'm missing some command I don't know how else to do it. Unless I have different vertex buffers for models that share everything bar UV co-ords.

Monday, July 07, 2003

I've done oh so little today.
Tommorrow I'm going to create a few small programs for DX, like I have been doing for Windows Programming and its various sprawling libraries.
For now I intend to finish the chapter on advance texturing.


Device->SetStreamSource(ModelBuffer);
Device->SetFVF(ModelFVF);Device->SetIndices(ModelIndices);
for(int i=0;i < NumMatrices; i++)
{
SetMatrix(ModelMatrix);
Device->DrawIndexedPrimitive(TRIANGLELIST);
}

Saturday, July 05, 2003

Yesterday learnt about scale, point sizes and transformations to the Graphics Device. You can do world transforms using matrices. So you can have a window with text on one side and the like. Also learnt about advanced texturing ... didn't finish though.
I need to get some small projects finished to make sure I can apply some of the theory I've learnt.

Wednesday, July 02, 2003

Yesterday learnt a little more of the GDI+, drawing lines from points and arrays of points, drawing ellipses using drawing lines and drawing ellipses which uses a rectangle. Drawing arcs and pies. That kind of things doing little programs as I went. Also went through Lights in my D3D book. Good but I need to apply it :).

Most cards support only eight lights at once! I guess if you had a level, you turn some off and on, reposition them as you go so it appears there are more lights than there are.

Tuesday, July 01, 2003

Big rant.
Or I had a go at hacking together my engine without really knowing enough and I got a bit stuck

Currently at an impasse. I need to organize my thoughts and the best way to do this, I find, is to write a long
rambling text that expresses them.

The issue is that of the tile scrolling and the camera moving.
The 3D realm provides me with new options compared to the previous 2D one.

Roughly the map is made from tiles. Each tile is a textured quad.
These tiles are placed upon the screen according to some data structure portaining to be the map.
Once placed we wish to move about this map that may be bigger than we can see.
But we don't want the clunky jumping movements of an entire tiles width or height at a time.
Instead we wish the map to scroll pixel by pixel.

The Way I Was Going To Do This
------------------------------

Each tile has no idea of its position in the world. Its not ever going to move, it need not know about its realtion
to the world at large. The map data structure takes care of this it knows where all the tiles go.

The map looks at its matrix, and says tile (0,0) you shall be plotted at the top left hand corner of the screen, and
all shall be good. Tile (1,0) you shall be plotted a the top of the screen 32 pixels from the first tile along.
In this way the map would blit all tiles to the screen.

Lets say our world is big, its made up of several maps in a meta matric structure.
A matrix of maps is the world, a matrix of tiles a map.

So we're in the corner of one map, we might be able to see into three other maps!
Therefore the screen needs to be built with chunks of tiles from each of these four (altogether) maps!
Therefore we would need a function
plotMapPartial(x,y, map, tile_x, tile_y);

This way we can plot any parts of a map we might wish to any area of the screen. This is a potentionlly complicated
function.

So what are we doing here - we have a fixed camera looking at the tiles.
Every frame we use immense computer speed to rearrange these tiles.
Maybe we move them all over to the right and introduce some new ones in the left hand column.
We can do this copmuters are zippy fast.
Then when the next frame appears on the screen - blammo - it appears we moved to the left.

UpSides: Pixel by Pixel Scrolling, Several Maps on Screen at once, Potentially unlimited world area
DownSides: Functions are on the complicated side



The Second Path
---------------

DirectX3D throws you into a world that already has some sublayer.
It knows there is an origin a (0,0,0).
All models are plotted according to this origin.
A sqaure will have some (x,y,z) that is its distance from the origin.
So we have these lines spreading to a tricorner of infinifty.
The world is plotted out, you can go some where in it and say "Here I am at (9,2,1)"

The key change that could be made here is we move the camera instead of the world.
Before we have a (0,0) and as we moved across we would slowly move new tiles into old tiles positions.
If we moved far enough in one direction (0,0) would eventually be replaced.

Instead we give each tile its own sense of place in the world at large.
Tile (0,0,0) is tile (0,0,0) no amount of moving about on the map is every going to change that

As we scroll the camera across the world we might move into an area dictated by a new map
say (10, 10, 0) we can see three new maps again but they don't need to replace any old tiles
They exits in the teens (11, 10, 0) and so forth.

The wrapping around the world problem! This is indeed a problem.
The only solution I can think of is a bodge, when we get to tile were there is no tile
we just load in the first map again.

So the to do list:

Decide tile sizes 32x32
Texture size will be 256 x 256
Chars will be a little skinnier 32X64 probably.

Done that.

Now assign texture co-ords


... an hour or two later

Okay that doesn't seem to work. What are my problems?
-My main render loop ends
-When I take a single interation out it runs okay
.. I don't see it on screen (see later point)
-Seems to hang on trnasforming co-ordinates, I could be doing this incorrently

Second
The map isn't as simple as I thought with global co-ords
(0,0,0) is center of the screen. To do the upper left hand corner I need negatives
This makes generating my tile coordinates not very easy.

I don't really now how to plot out a level - i.e. I need to learn more

Monday, June 30, 2003

I've sketched out this so far. I'll be filling in the details.


using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D=Microsoft.DirectX.Direct3D;

namespace EIN.axiom
{
// The base class off all things represented by vertexes in my world
// Chiefly used as an include in tiles and characters
class Model
{
//1.Indivual Transform Matrix group
//2.Reference to a vertex buffer
}

class AxiomEnginge
{
// Might this be world
//Hold vertex buffers for the models,
//Create common and custom vertex models
//Help out with the rendering
// Texture stuff
// Methods for creating Tiles with a nod to textures
}

class Tile
{
private model TilePiece;
//all other tile realted stuff
}
}

Read Chapter6 of my directx book. Proven enlightening. I think I should now be able to create my tile engine. Its thrown up a number of question. I'll discuss these questions as soon as I implement it which shouldn't be too long now.

End of the week: Scrolling multiloading RPG vertexual engine

So that should be fun fun cool.

Sunday, June 29, 2003

Not done too much today far too sunny. Though a good thread here. All sounds a little complicated though. I intend to have a try tommorrow.
Just polished off chapter 4 of my programming windows book, yesterday. Don't know if I'll do anything today.

Friday, June 27, 2003

Not really progressed too mych from this morning.
Read a article on 2D using DX8 but it was true 2D not vertex processed.
Mentioned a sprite interface, I cant find it in the DXutils and DX3D extra helper modules for C#
Bah.
I've been routing around function calls.
Got some cool web articles that I need to read through.

Top Priorites:
Another few chapters of my 3D book! (Done by tommorrow)
Tile a set of polygons across my window, from higher order functions
Oh I also have a full screen mode working now as well. Certain parts of the device property must also be set.
Yesterday I read two chapters in Programming Windows in C#.
I'm getting a better grasp of delegates though I need to get a program where I fiddle with the code myself going.
The chapters are massive though :(
It's not such a bad book on the whole so far.
Ah-ha using the same vertex buffer I've now drawn two matrixes in different places in my world.
I'm not sure I've done it the correct way but it seem to work.

Call DrawPrimatives from the device and drawn my quad.

device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

The first 0 being the vertex to start with, the second 2 is the number of triangles. In this case two to make a square.
There seem to be calls to draw rects and such but this way is good for now. I can, if I so wish, have odd shapes in my world.

So that sets the first one down at what is 0,0 dead center of where I am looking.
This seems to be where 'I' place no matter what.
Therefore I need to move myself, place and move myself back.
There are the three Transform types, world, view and projection. I can't really remember too much about each. Projection can be thouht to be the lense of a camera it deals wit transforming 3D co-ords ot 2D space. I'm not sure of the differences between view and world. Here I change the view.

So I create a matrix, they have handy functions to be tinkered with.

change.Translate(10,1,0); // I've called my matrix change.
device.SetTransform(TransformType.View, change)

These are x, y, z. So I was it to move 10 units on the X, and 1 unit on the Y.
So then I change the view vector.
Then I call the draw primatives with the same call again.
Then I cal translate with negative numbers to return me to my origin.
Then set the transform to the view again.

If I don't return to my starting position I can only see the most recently placed I'm not sure why. It could be do with my movement calues or mixing view and world up.
Ah-ha one vertex buffer per model!
Make more sense.
I guess a vector of vertex buffers and then render that? or something based off that so you know how many vertex buffers you wish to render.

Wednesday, June 25, 2003

What was done yesterday:
Looked into the first few SDKs tutorials reasonably deeply. that was pretty much it :(

Today - had a look though an old tutorial for DX8 in C++. Converted it and messed around. The code is a bit of a hack job and is overwriting the 3rd SDK tutorial example.
But it works - images to screen orthagonal view.
Currently awfully user unfriendly. It needs wrapping into a nice class.
I want to be able to plot a said polygon and a said place with a said texture with a few function calls.

Currently it puts the polygon on the screen with a bitmap texture.
I'll have mess with the code and make it nicer today / tommorrow and the write the important bits out here.

I only want to unlock / lock the vertex buffer once per frame so I need figure out a way to but all my graphical changes in a group before sending them off the the unlock lock buffer.

Tuesday, June 24, 2003

Okay so its currently in Windowed mode that needs changing or giving an option to change.
Currently its simply and I understand most of it. There seem to be some uncessary uses of delegations but I left it like the tutorials give it.

The Simple Overview
1. Create a window / from
2. Create device, in this case a 3dDirectX device. Linked to the form
3. Create a vertex buffer
- lock the vertex buffer
- stick in all the vertexes you want to render, in an array
- unlock it
4. Render by adding it to the scene while the scene is locked in the render function.

All the stuff going to the screen has to go through the render function. Meaning it has to go through the vertex buffer to get there. Or they're the looks of it so far.
This is using the tutorials avaliable at the Microsoft site.
Going through the window C# book might be an idea too.
There are only five tutorials and my disk copies differ from the web copies slightly. Though they all work, they don't provide much background though.

So I've got to polish off the last three tutorials. I'm going over them slowly making notes. These should be useful later for when I try to tie in my book on DirectX for C++.
What work occured yesterday:

-Wrote a small console based game that uses inheritance and dynamic binding as well as overloading. Just to make sure I still had my flow. It seems I do as that worked fine. It would have been much harder in C++.
-Finished C# For Programmers. A very good book, I now feel I have a broad understanding of the language.
-Wrote up some of my 'broad understanding of the language notes'
-Read a chapter of a book specifcally based on the C# IDE, i.e. the .NET IDE so far its pretty worthless.

What I failed to do:

Get a bitmap on the screen Bah!
It doesn't seem too hard in the GDK+ but I want to use Direct3D.

Todays plan:
-Write up notes.
-Do SDK tutorials right up until the end. They may seems like gibberish to me but using the Direct3D book I should be able to piece together the meaning.
-Have a look at the other C# books specifically the windows one and do a few chapters.

Monday, June 23, 2003

Last week I've been working my way through a book on C# for programmers. In a ringbound smallish notebook I've made a few notes as I've gone along. I'll digitize them now, which should refresh my memory.


My C# Notes

The .Net frame work is component based. All C# objects can be thought of as components.
Each object is associcated with metadata, i.e. data about that object.

Each program requires a main function.



public static void Main(string[] args)
{
}



The main function is static. Main is the function that controls everything, static prevents you creating more instances of the class containing the main function.

Code is seperated into classes. Its an OOP paradaigm so each class should attempt to represent some distinct object. Classes that interact with each other, are grouped together in the same scope space. These spaces are defined using the namespace keyword. Namespaces are used to group and order classes, they can be nested in each other much like Russian Dolls.



namespace DanSpace
{
//classes concerning the operation of DanSpace
}



Once these namespaces are carved out, other parts of the program can gain some level of access to them by using the using keyword. You may want to use a deeply nested namespace this can be done by using an alias.



using theConsoleClass = System.Console;
...
theConsoleClass.Writeln("I'm using an alias!");



.Net allows you to write in any programming language it supports. You can the package up whatever you've written and access its functionality in any other programming class. Package up some code is turning it into an assembly. To access other users objects in assemblies you must locate them and add them as references in the IDE.

Structs exist in C# also. They are mainly used for lightweight datatypes. Made to be used as the built in datatypes are used. So adding matrices or vectors or complex numbers etc.

Attributes are a part of the metadata mentioned earlier. Attributes are stored in square brackets.
e.g [Code Review("1.02.2003", Comment = "Well Done"]
The specific of the attribute are defined usng a special class we'll come to later.
Attributes can be accessed during runtime!

C# supports exception heavily. Rather than have some function returning a HRESULT choc-a-block with various error codes, errors are thrown as exceptions. This makes the code much less buggy, as error handling is seperated and all the expensive checking and such is used only when needed. If an error occurs the program throws it down the code, until it reaches the relevant ctach statement. If it doesn't find the catch statement, it goes up a level in scope and tries again. If it once failes all the way to the top level of scope a little window will come up and the program will be halted. Such as DivdeByZeroException press okay.

They work like this



try
{
int j = 9 / ZERO
}

catch (DivideByZeroException e)
{
//Do correction code.
}



A catcher might do some clean up code and then throw the exeception again. It may throw a new expection so another program can do some more cleaning up.
Users can defined their own expections. Using inheritance and making sure to use the right overloaders.



public class CountIsZeroException : Exception
{
public CountIsZeroException()
{
}

public CountIsZeroException(string message) : base (message)
{
}
}



So there's the new exception and we might use it as below.



public void DoAverage()
{
if (count == 0)
throw( new CountIsZeroException("Zero Exception in DoAverage")
else
average = sum / count;
}



The Finally keyword, with all these exception hoping out at unknown times, it may leave resouces open, and not properly shut down. Such as I/O for example. This is where the finally keyword comes into play. No matter what before a function is exited the finally cdoe block is called.



finally
{
file.Close();
}


Classes

myPoint.GetMyPoint(ref x, ref y);
X and Y must both be intialized

myPoint.GetMyPoint(out x, out y);
X and Y do not have to be intialized


Overwriting

If a base class has a function 'foo' and the inhertiting class has a function 'foo' which is an unrelated class. Then the child class must make this clear to the complier by adding in the keyword 'new'.



public new update ( params )
{
}



What if we wish the function to replace the base classes function? The base function must be declared to be virtual and the child must use the override keyword.



virtual public update(); // in base class

override public update(); // in child class



Now if the child class was referenced as the base class and the update function was called, then the complier would check the type of the object. It would then check if the function was overridden and if so would call the overriding class.

So new is for a seperate unrelated class that happen to share the same name
But virtual and override mean that the functions is to be overwritten by its child function.

Programming Style: The Virtual Keyword should only be added when used. (only added when there is a base class overriding)

Abstract Class

An abstract class is a class with one or more abstract functions.
An abstract function is a function that has no functionality. Its just saying there should be a function that takes this and this and returns this.

An abstract class therefore can be instaiated. You cannot create a class with function that have no code.
Any child of an anstract class that is not abstract must include code for the abstract functions. Using the override keyword.
This is a powerful enforcing tool.

The Sealed keyword means a class cannot be inherited from.


sealed class MyClass
{
}


Class privacy

Internal - used to write helper classes, that you would rather the final user of the class did not see.
access to the class is avaliable to all classes in the same assembly.
it can also be used on members of a class, when you wish to share members but not allow public access.

Internal may be combined to internal protected. So that those classes accessing through protected or internal have access.

Classes as we said earlier can be nested. This is useful if only the current class is going to make use of that type of object. Not only classes can be nested in classes so can structs, enumerations and interfaces.

Constructors

A function that is called as soon as an object is created from the class.
The function must be public, share the same name as the class and not have any return types.
It is often useful to call the base classes constructor first and this is done as following:



public class Derived : BaseClass
{
public Derived (int x) : Base(x)
{
}
}


Constructors often repeat a lot of code, for the various ways they can be constructed. Usually building up from simplier intializations in this way forwarding can be useful.



public MyObject(int x)
{
this.x = x
}

public MyObject(int x, int y): this(x)
{
this.y = y
}



The second constructor calls the first. Less code has to be written.

Elements in a class can automatically be intialzed to some value.
This is done simply int x = 0;

Static members and functions are those that are not asssociated with any particular instance but rather the class itself in general.
One of there uses is as class counters.


class MyClass
{
public MyClass()
{
instanceCount++;
}

public static int instanceCount = 0;
}



Outside of the class, in the main code. To access the static member the class name must be used not the name of one of its object instances. So it would be MyClass.instanceCount, rather than someObject.instanceCount. That would not work.

Static constructor can also exist, before the first objecti s intialized the function is called and my do necessary setup work.

Constants use the keyword const, and must be set at compile time, they will not change.
If we wish to have something like a constant but do not know its value until the program is running the readonly keyword can be used. Once assigned a value this value cannot be changed.

If you choose to create a class of all static members it is best to declare it private so that it cannot accidently be initailized.

Creating A Variable Length Parameter List

Such as writeln(string1, string2, .... stringn). They can all be written out. This can be achieved in user-defined classes also. The keyword params is used.



//first deal with the single argument condition
public void Write(string label, object arg)
{
}

// the deal with the n-case, an array of arguments
public void Write (string label, params object[] args)

params keyword means that the function will accept variable length arguments.
It is good programming practice to include a few function for some of the simplier cases also. I.e. one argument, two arguments, three arguments and the array of arguments.

Structs

Structs are cheap fast to allocate and do not have a reference overhead.
They are the same as classes but
- cannot inherit from any other type
- other classes may not inherit from them

They should only be used for the basic types.

Interface

Interface classes are those classes that have all there methods abstract. A class may inherit from more that one interface but it may inherit only from one class.



interface IScalable
{
void ScaleX(float factor)
void ScaleY(float factor)
}

foreach (DiagramObject d in dArray)
{
IScalable scalable = d as IScalable;
if( scalable !=null)
{
scalable.ScaleX(10.0F)
scalable.ScaleY(10.0F);
}
}



The as keyword changes all objects to the type after the as, or sets the others to null, if it cannot be explicitly converted.

Choosing between Abstract and Interface: - If objects derived from base class would cary widely then Interface is the more suited choice.

Bits and Bobs

Case statements are more efficent than nested ifs.

foreach example


foreach (MyObject current in arr)
{
Console.Writeln("Item: {0}", current);
}


It can also be used to iterate across the keys of a hash table.

Blocks of code can be put into checked status by:


checked
{
//code
}


Any overflows will then thorw expections. Going out of range by repeatadly adding to a byte etc.
The entire program can be put into check by cheking a falg in the ide.
Then when you want something now to raise the exception you should but it in unchecked blocks.

Remainder (I always forget this one so I'm putting it in) x % y =~ x-(x/y) * y

Conditional operator

? :
int value - (x<10) ? 15 : 0;
If the condition evaluates to true then value is assigned 15 otherwise 0.

TypeOf - reutrns the type of the current object
Is - can an object be converter to a particular type, returns a bool.

Arrays

Operators: Reverse(), IndexOf(), LastIndexOf(), Sort(), BinarySearch()
The sort works for built in types and cane be extended so that it will work for user defined types also.

Accesors


public string Name
{
get
{
return Name;
}

set
{
value = Name;
}
}



If you have a getter only its is readonly.
If you have a setter only its is writeonly.

These are useful for effecient loading.


class CarDealer
{
public int ProductionCount
{
get
{
if(productionCount == -1)
{
// do expensive load operation from the database
}
}
}

int productionCount = -1;
}



Use the negative value of -1 to mean that we have not read in from the database. Thereby only doing a database access when need be.

Enumerators

Useful for a value in a program can only have a certain set of values.
Enumerators can also be used as Flags bits allowing them to be comibined using logical operations.


[Flags]
EnumBitValues
{
{
NoBits = 0;
Bit1 = 0x00000...1
...
}
}


Attributes - annotations that are placed in the source code.

Delegate

A bit like type safe fuction pointrers.
They are created at runtime and specify the form of a single function.
If two delegates are added together a delgate that calls both functions is the result.
Useful for when you want to change the behaviour of a function.

Example: A sorting function where the delegate defines the comparision function.



public delegate int CompareItemsCallback(object obj1, object obj2);

public void Sort(CompareItemsCallBack compare)
{
//inner loop
int order = compare(item1, item2)
}

public class Employee
{
public static int CompareName(Object obj1, Object obj2)
{
Employee emp1 = (Employee) obj1;
Employee emp2 = (Employee) obj2;
return(string.compare(emp1.name, emp2.name))
}

public static int CompareId(Object obj1, Object obj2)
{
//compare ids
}
}

...

//Main Function
//Create Delegate To Sort by Names!
Container.CompareItemsCallback sortByName = new Container.CompareItemsCallback(Employee.CompareName);
employees.Sort(sortbyName)

}



THats how delgates work how fiendishly clever. Things though can infact get cleverer. In the book I was perusing things got incrementally clever-ver. Rather than do that I'm going to jump to the last step of cleverness.

Create the delegates on the fly rather than always having them present.


public static Container.CompareItemsCallBack SortByName
{
get
{
return( new Container.CompareItemsCallBack SortByName
}
}



Now only created when needed.
Events - a class can use events to notify another class/ classes that something has happened.
Publish / Subscribe idiom.
A class publishes events it can raise. Classes that are interested in a specific event can subscribe to it.
Often used for GUIs, but can also be used for things like mail handlers.

User Defined Conversions - allow conversions between classes and structs and other objects in the system. The example for this was pretty awful.
Basically you have to take in account if you may loose data or not. Epxplicit and Implicit conversion. Currently I don't see myself using it so I've skimmed it.

Infix Operators!

We use the operator keyword to allow a class to use the +, - and others. Overload them!

public static Datatype operator + (Datatype D1, Datatype D2)
{
//Do the jazz return the result
}

Preprosssors



#define DEBUGLOG

...

//In code
# if DEBUGLOG
Console.Writeln("Main - Debug is enabled");
#else
Console.Writeln("No Debug in Main");
#endif


Verbatim Strings
Removes some of the string processing so you can write exactly what gets printed out.

string = "C:\\Program Files\\Microsoft Office\\Office"
instead we can have
string = @"C:\program Files\Microsfot Office\Office"

It will also keep all tabs and newline you phyically put in, using vertabim strings may span several lines.

Making Objects the fit in with the dotNet frame work

All objects have the operators '==', '!=' and toString. These can be overridden so that they are more useful.

ToString:

override public string ToString()
{
return ("{0} \n {1} \\ {2}", name, health, hits);
}
...
Console.Writeln("Pete's health:{0}", pete);
//Writes out pete name and what health he has out of his total



Equals() used by collections(hash tables, arrays ...) for ordering . For more useful ordering it should be overwritten with code that says when two of your classes should be considered equal. For example two pieces of wood should only stack if they have the same durability.


public override bool Equals(objects obj)
{
Item item2 = (item) obj;
if durability != item2.durability
return false;
if name != item2.name
return false;
return true;
}



Once equals is defined its easy to write in the '==' and '!=' equals operators.


public static bool operator == (Item I1, Item I2)
{
return(I1.Equals(I2));
}

public static bool operator != (Item I1, Item I2)
{
return(!I1.Equals(I2));
}



These operator '==' and '!=' must be overloaded as a pair. They cannot be overloaded seperately

GetHashCode() must return a unique integer id for the object. This id must be related to the value(s) used to determine if the object is equal or not to another object. If there is a unique field in the object it is probably a good idea to use this as the hash code.



public override int GetHashCode()
{
return(unique_id);
}



If there is no unique Id then one should be created from a function of values.

Making User Defined Types Sortable

Simplest way is to implement the IComparable interface.
This allows you to add sorting, but sorting only one way. What if you wanted to sort by different field, name, age, shoe size, well we'll come to that afterwards.

First the IComparable Interface



int IComparable.CompareTo(object obj)
{
Employee emp2 = (Employee) obj;
if (this.id > emp2.id)
return(1);
if (this.id < emp2.id)
return(-1)
else
return(0);
}


So a int for the three possiblities of greater than(1), less than(-1) and equal(0)
This could be seens as a default sort. Though it does not let the user deicde what he would like a group of classes to sorte by.
To do this the IComparer interface must be used.

The sorting classes are nested in the class they define the sort for.



pubic class Employee : IComparable
{
public Employee() {} // constructor
int IComparable.CompareTo(Object obj) //default sort

public class sortByNameClass : IComparer // User defined sort using nested class
{
public int Compare(Object obj1, Object obj2)
{
//Do comparision using string.Compare
}
}
}

....

// In the main body of code
Array.Sort(arr, (IComparer) new Employee.SortByNameClass());
//Now the array is sorted by name


The syntax is a little messy with the 'new Employee.SortByNameClass());' The user shouldn't have to create a new object, if we make it staic the call be comes a lot simplier as the class doesn't have to be intialized.



public static.IComparerSortByName
{
get
{
return( (IComparer) new SortByNameClass());
}
}

public static.IComparer.SortById
{
get
{
return(IComparer) new SortByIdClass());
}
}



These make the calls to the instaitated the classes, so the user no longer has to instead he just calls the accessors.
As below:


Array.Sort(arr, Employee.SortByName);


For completeness the Relational Operators should also be overloaded.
(<,>, <=, >=)
This is done as before. Note they must be overloaded in pairs you cannot just overload one.

public static bool operator < (Employee emp1, Employee emp2)
{
IComparable icomp = (IComparable) emp1
return(icomp.CompareTo(Emp2) > 0);
}

Advanced Hashing

Very similar to adding new sort classes.
When you wish for an object to have more than one hash. i.e. based on the EmployeesID and another based on the EmployeesName.
IHashCodeProvider Interface should be used.

IClonable

Object.MemberWiseClone();

Creates merely a shallow clone. All references are copied, rather than creating new objects to be referenced to.
What is needed is a deep copy, where new objects are created.
This is done by implementing the IClonable Interface


class ContainedValue
{
public ContainedValue(int Count)
{
this.count = count;
}
public int count;
}

class MyObject : ICloneable
{
public MyObject(int Count)
{
this.contained = new ContainedValue(Count);
}

public Object Clone()
{
Console.Writeln("Clone")
return new MyObject(this.Contained.Count);
}

public ContainedValue Contained;
}



Some brief I/O



class Test
{
public static void Main()
{
FileStream f = new FileStream("output.txt", filemode.create);
StreamWriter s = new StreamWriter(f);

s.WriteLine("{0} {1}", "text", 55);
s.close;
f.close;
}
}


Style

PascalCasing - anything that would be visible externally from the class
camelCasing - private members, method parameters.

Interfaces should start with I.

Assert

using System.Diagnostics;

Debug.Assert(i==0, "BadState");

If i equals 0 then bad state is outputted.
In main:



Debug.Listeners.Clear(); //remove default Error Outputs
Debug.Listeners.Add(new TextWriter.Trace.Listener(Console.Out));



The default output is a windows message box, here its changed to the console window.

WriteIf and WriteLineIf, only write out if there first parameter is true.
Debug.WriteLineIf(debugOutput, "In VerifyState");
Aim for today: Get textured bitmaps to the screen via some loadbitmap function.

Detail: Basically I'd like to do this using a 3D framework. A screen full of quads each a tile each with a tecture.

I've been fiddling with Direct X. There are hardly any web tutorials dealing with DX9 and C#. The Microsoft SDK is a bit lacking and 'subject to change' bah.
I may use the GTK or whatever its called instead. Its a lot simplier and I can write my code in such a way that I cam swap in some faster later.

Right now I'm going to read this and see if things suddenly become clearer.