Converting CSBWin graphicengine to a OpenGL 3D engine

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Bit »

Rasmus, that's how it ever came into my mind how to do it - if that really can be realized, go on!
User avatar
linflas
My other avatar is gay
Posts: 2445
Joined: Tue Nov 04, 2003 9:58 pm
Location: Lille, France
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by linflas »

I tried last version and played a bit with textures in WallsetUnderground.
- I'm surprised by the floor bitmap : it's a 256x96 rectangle and if i change it to a 256x256 square, some rectangle-ish stone texture and it looks really weird : i feel being on the top of stairs all the time. And the tile is resized, it doesn't look square but rectangle. The interesting feature of it is the powerpink color used for transparency : lots of possibilities for organic or nature wallsets !

for future releases :
- could it be possible to view further, i.e. 5 tiles ahead ?
- accept higher resolution bitmaps for texture/objects/monsters
- png format supported (with transparency) ?
- crypt/hide bitmaps
"The only way out is another way in." Try Sukumvit's Labyrinth II
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

@bit:
Yeah, it feels really nice. I got this feeling that everything I do gives progress to both the game and the editor at the same time.. Keeps the motivation up :)
It wasn't that much work either accually.. All I did was compiling CSBWin as a dll file, and let the editor load it with a new thread. In this way I can send messages back and forth. CSBWin feeds the editor with map information and CSB bitmaps, and the editor feeds CSBWin with the changes it wants it to do. Really fun accually :)

@linflas:
Ahh, that one is alittle bit tricky, the reason I made those in 256x96 is because I raised the farmost part of the floor. I did this so that the wallset would get a little bit more caveish effect. This can be changed if you enter the editor, press "Edit wallsets", locate the "Type:floor" and then press the button "Checkout wallset" in the lower left corner.. Here you can move around the floor so that it looks like a wall if you want to :) Otherwise just press "reset" and it will get plain..
There are some opimizations here to get it right..

- could it be possible to view further, i.e. 5 tiles ahead ?
No problem, it is just to change some varibles and it is done. But the light distance would also have to change with this..
- accept higher resolution bitmaps for texture/objects/monsters
I thought it did support almost as high res as anyone wanted it to be.. But I will doublecheck..
- png format supported (with transparency) ?
I can fix that..
- crypt/hide bitmaps
I am not sure what you mean here.. Could you explain alittle bit more?
User avatar
linflas
My other avatar is gay
Posts: 2445
Joined: Tue Nov 04, 2003 9:58 pm
Location: Lille, France
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by linflas »

Rasmus wrote:No problem, it is just to change some varibles and it is done. But the light distance would also have to change with this..
then, a "fog distance" or "fog factor" value has to be applied to level.
this would be a great enchancement for outside wallsets, shade color should be editable as well (light cyan for a subtle fog effect for example).
Rasmus wrote:- crypt/hide bitmaps
I am not sure what you mean here.. Could you explain alittle bit more?
i mean for non-spoil purpose. if future player can browse bitmaps into directories and see how the final boss looks, where's the surprise ?
"The only way out is another way in." Try Sukumvit's Labyrinth II
User avatar
Lord_BoNes
Jack of all trades
Posts: 1064
Joined: Mon Dec 01, 2008 12:36 pm
Location: Ararat, Australia.

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Lord_BoNes »

@Linflas: Do you mean like how RTC "hides" (and obfuscates) the dungeon resources within the *.RTC file? As far as I'm concerned, that feature is a MUST have, otherwise people would just go around hijacking peoples graphics & sounds.
If the designer chooses to let a person (or people) have thier resources, then that's thier choice. Like it should be.
 
Image

1 death is a tragedy,
10,000,000 deaths is a statistic.
- Joseph Stalin

Check out my Return to Chaos dungeon launcher
And my Dungeon Master Clone
User avatar
linflas
My other avatar is gay
Posts: 2445
Joined: Tue Nov 04, 2003 9:58 pm
Location: Lille, France
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by linflas »

exactly
"The only way out is another way in." Try Sukumvit's Labyrinth II
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Gambit37 »

Looking like some nice work going into this. The lighting is very strange though -- what are all the weird dark triangles all over the place? Can this be fixed?

Image

I would so *love* this rendering engine to power RTC or DSB.... with this engine and their editing capabilities, we'd TRULY have the ideal modern-but-retro-3D DM I think we've all wanted for years... :-)
User avatar
linflas
My other avatar is gay
Posts: 2445
Joined: Tue Nov 04, 2003 9:58 pm
Location: Lille, France
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by linflas »

that "checkout wallset" screen looks so much like RTCWM :shock: !!
"The only way out is another way in." Try Sukumvit's Labyrinth II
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Gambit37 »

Yes, that's a very sweet feature!! :-) Gosh, there's so many cool things spread over so many engines -- imagine if we could take the best of each of them and make one uber engine, we'd have my ideal platform:

* The 3D rendered display of CSBWin3D
* The wallset editor of CSBWin3D
* The visual interface of RTC editor plus all it's extensibility
* The advanced IA of DSB and its LUA approach to editing

Whos' up for it? :) :) :)

(By the way, I'm not dissing any of these tools in my list, or forgetting the other cool stuff that they can do -- I'm just listing the features of each engine that most appeal to me personally.)

@Rasmus, some questions

1) Do images have to use power pink for transparency, or can we used PNGs with an alpha channel?
2) If we use high-resolution imagery and set a large window size (1280x800 for example), will the images automatically be scaled to look as good as possible?
3) How do I use/remove a heightmap? I can't work out the editor for this... I managed to create a large area of yellow, but now I don't know how to remove it?

By the way, the heightmap is a very cool feature -- however, I think you need to change the angle of the camera when the player is on a very steep slope, so that they can see up or down to what's ahead -- and/or provide a lookup/lookdown feature?. See these screens for the steep slope problem:

Image

I am in danger of becoming the George Broussard of custom dungeon creation -- can't settle on an engine! ;-)
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

The bitmaps will be hidden in future releases, this release is still for experimentaion.. So don't go away and make a 200 level map in my editor just to find out that the real release is on the way ;)
Fog distance implemented with the wallsets are a elegant sulotion!
that "checkout wallset" screen looks so much like RTCWM :shock: !!
Sorry for beeing a copycat, but that sceen just had to be shown ;)

The thing about this engine is that it doesn't do any dungeon building at all, this have to be done with csbuild or some simular editor. It just enhances CSBWin with almost all imaginable visual effects. As I go along I will insert some other stuff like maybe a two handed fighting system.. As I have been digging into the CSBWin code for almost an enternity now I can make almost every change posible, so just pop some questions of features you would like to see and I will try to insert them..
But this engine woun't be able to power RTC or DSB unfortunaly, I did try with DSB, but I just don't have the time to get use to a totaly new sourcecode.. But as I said, anyone that want new features inserted, just ask.. I really like experimenting to see how far I can take the code :)

The lightning problem (dark triangles) will be fixed!

PNG with alpha chanels will be fixed.
CSBWin3D will support as high resoluion on the textures as you want to, and the game can also be set in almost any resolution posible both windowed and fullscreen.

The heightmap can be changed by setting the lift power value, also try changing the blendtypes for diffrent heigtmap blendings. When you are done you can press the "smoothen heigtmap" button to get rid of the to heavy tile to tile diffrences in the heightmap.

Adjusting the camera after the sloop sounds like a good idea. This will be fixed :)

I did post this screenshot earlier, but this feature will also be implemented with future releases
Image

Just to show that the GUI can be changed to the extrem. Like putting the dungeon viewport in fullscreen and then have transperant menus/buttons/bars over it..
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Gambit37 »

HI Rasmus. Yes, I understand you're not making this into a full dungeon editor. I just like tinkering with the tools that people produce, and it's very cool to see the old DM engine with a new 3D twist. ;-)
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Now I really want to curse alittle!! I haven't said anything before but I really HATE following the codeflow in CSBWin because of those RESTARTABLES, I am speending half my time trying to get rid of them just to find some more #@!%!!!
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

The reason why I get allittle bit angry about these is because I want to be able to restart CSBWin without having to reload it. So when I restart it I reset the DBank and other varibles of importance, but there is still those RESTARTABLE functions that have static values in them. They all have a value called myState that are edited only within the function decleared by RESTARTMAP. This value starts with 0 and then changes as the function gets called. Here comes the annoying part.. When I want to restart CSBWin I can reset all global instances but not those that are decleared within the function, so they just continue where they left of..
So the last myState value _AskWhatToDo had was to terminate the program, but that is not the value I want it to start with...

There are one ways to fix this.. It is to add an boolean input varible to all those 200 RESTARTABLE functions that tells the function to clear the myState value..
But I don't like it, the code gets really crappy..
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Anyway, I finally got it working.. But it is annoying when almost all code are decleared as instances, harder to collect the garbage that way..
Fixed the RESTARTABLES with declaring a global boolean and by adding some extra code in the RESTARTMAP defenition that would reset the state and then return if the global boolean was true, this meant that I also had to call all det RESTARTABLE functions in the start.. Not pretty, but hey, how is watching?! ;)
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Bit »

This is why I use Allegro (and there is Allegro-GL too!). It simply wraps that evil WinAPI, and in the .cfg-file I can choose if I want to use GDI or DX, fullscreen or windowed. There are also precise timer-functions, and one can switch mouseinterrupts etc.
Okay, in my builds I do some polling, but nowadays computers are fast enough to compensate this. But it avoids such construction. Still, if Paul had to use them, there must be a reason for.
Personally I hate things like those, after all you don't know where you are, if you didn't program it yourself. Maybe it is pretty flexible once you understand it, no idea - but it fooled me while debugging some times.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Gambit37 »

I fail to understand anything written after that pretty picture above! ;-)
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Bit »

Gambit37 wrote:I fail to understand anything written after that pretty picture above! ;-)
I just want to ensure that we get more of those pretty pictures by giving him a heads-up :)
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Yeah, they probably had a purpose in the beginning when debugging, but they are begining to fade away one by one.. And I wount call them all that evil, Paul has probably full use of them, but they may see complicated for a outsider trying to understand them.. Anyway, I learn something new every day :)
Gambit37 wrote:I fail to understand anything written after that pretty picture above! ;-)
I was just summoning Bit ;)
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Paul Stevens »

bit wrote:Okay, in my builds I do some polling, but nowadays computers are fast enough to compensate this.
The purpose was to maintain the exact structure of
the Atari code while, at the same time, complying exactly
with the spirit of Window's event-driven paradigm.

One advantage of using no polling or timed waits
is that it can go really fast in playback mode without
any special tests.

A couple of 'Sleep's got stuck in there when I got too
lazy to construct a stack of 'RESTARTABLE' functions. :-(
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Well I'm starting to get a hang of it now, so now I am alot happier :)

But then again, I am facing a new problem..
The CSBGame.dat savegames are giving me alittle bit of a headace. The reason is that because I am doing an editor, I don't want to use only those CSBGame file in the current directory when saving, this means that I am using a OpenFileDialog when saving games..
It all worked fine until I started I noticed some problems like that I wasn't able to press on menubuttons or pick up items. As usually when this happends I check if I have expanded a array somewhere or was writing a to large array to a pointer..
I first got a clue when I was working on the Disk Utility because I wasn't able to start a new adventure.. There I noticed that when I was saving the game the filename also got written to the savegame. This was a problem because my filenames included directories and was therefore far larger than the "CSBGameX.dat" files. I guess that the pointer I wrote to had a memoryadress close to some other poiters that then got overwritten. And that the result was creating mumbo jumbo rectangles for itempicking..
I solved this by just writing "CSBGame.dat" to the savegamefiles but still save them where I wanted to..
This worked nicely until the next problem arose, when running the Utility Disk again on the same save game that I saved before just gave me a "SAVED GAME ERROR".. The reason for this seemed to be because of a checksum that didn't added up.

So for those of you that had the patience reading my little story maybe have some tips on what it is that doesn't add up here. I haven't made that much changes, the only thing I am trying to do is saving the games with diffrent names than "CSBGameX.dat"..
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Paul Stevens »

I was working on the Disk Utility
God help you. I still have no idea what that
part of the program does. I think it must have
been written in 'SmallTalk' and translated to
'Lisp' using a shell script. (just kidding...but not
much)

If there is anything I can do to help with the
filename/checksum problem, let me know.
Perhaps we could:
1) Change the name in the data before computing
the checksum.
2) Ensure that we only put the last 12 characters
of the name into the data to avoid any overwrites.
3) Put a 12-byte hash of the name into the data.
4) Put the last 11 bytes into the data plus a one-
byte hash of the rest of the name.
5) Set an 'IgnoreChecksum' flag (I don't like this
at all :!: )
6) Other ??
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Thanks for the info Paul.
I have checked if it is only a checksum problem but it seems to be more than that, almost like I alter the data inside the savegame unintentionally.. If I ignore the checksums I only get a big error!
The savegame loads and saves fine in the game. But the utility don't seem to like it..
Now I am checking if the filename I send into CREATE(char *name, char *flags, bool dieIfError) or OPEN(char *name, char *flags) saves the filename somewhere or use it when writing the savegame.. Because those functions are the only functions I send the full filename to.. All other varibles are set to "CSBGame.dat"..

I have also noticed that you have wrote "// TRAP" after some of the CREATE functions.. Is this something I should be worried about ;)
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Something else I am worried about when checking the CREATE functions
the savegame filenames are saved into the FILETABLE::m_fileName and used in the FILENAME::m_name when creating three files..
The second one I can easely avoid, but I am alittle bit worried about the FILETABLE::m_fileName varible..
This varible uses malloc storing the filename.. And I have a bad experience with those because they just enlarges the buffer they need straight forward without checking if that memory already is occupied..
An problem like that can easiely corrupt the savegame.

Well, I will give it a try and check if this is what is causing the problem..
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Hmm, found something interesting here..
The CSB src Clone-CSBwin-SourceCode-11_014.zip at http://dmweb.free.fr/?q=node/851 also generates the same problem..
Seems like the CSBWin11_014 has updated the savegame and didn't let the utility tool in on it..
CSBWin11_014: CSBGame.dat have a size on around 25kb at the choose champion dungeon, one character. While Clone-CSBwin-PC-ChaosStrikesBack-100 have as size on around 21kb at the same conditions, and this one loads nicely with the utility tool..

Okey then, now I know it wasn't me :)
I guess all I need to do know is check and fix so that the utility tool loads the savegame in the same manner as the game does..
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Olalala.. Works!!
Found the problem at the line.. in chaos.cpp

Code: Select all

D0W = MyUnscrambleStream(LoadPnt(A4+4104), //Timers
                          10 * LE16(wordGear(A4+578)),
                          LE16(wordGear(pnt_4646+6)),
                          LE16(wordGear(pnt_4642+6))  );
The size decided here is "10 * LE16(wordGear(A4+578))" = 2970

While when saving the game at the line.. in savegame.cpp

Code: Select all

    int timerSize;
    timerSize = sequencedTimers?sizeof(TIMER):10;
    D0W = UnscrambleStream((pnt)gameTimers.pTimer(0),  // buffer
                          (ui16)gameTimers.MaxTimer() * timerSize,// # bytes
                          b.gb1.TimersHash,      // initial hash
                          b.gb1.TimersChecksum); // expected checksum
Where the size "(ui16)gameTimers.MaxTimer() * timerSize" = 3564

So.. (2970 / 10) * 12 = 3564
Meaning that the timerSize varible was equal to 12, while at chaos.cpp it had a constant value of 10..

So I have fixed it and inserted a timerSize varible into chaos.cpp making this headace go away :D

Here is a download of the working chaos.cpp..
http://www.rasmus-dev.com/misc/chaosfix.zip
It should be inserted into Clone-CSBwin-SourceCode-11_014.zip to fix the utility tool.
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Paul Stevens »

Oh, WOW! Thank you so very much for your time
and skill in debugging this problem.

Fixing anything in 'Chaos.cpp' deserves some sort
of medal. A Purple Heart might be in order.
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

You can call me Fixmus :P
No but seriously, it's those problems that keeps my motivation running.. If everything goes on to smoothly I just get bored..
User avatar
Paul Stevens
CSBwin Guru
Posts: 4318
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Paul Stevens »

I think you are working with an old version of
the source code. The fix you propose appears
to be present in the newest source. The newest
source is 11.067 and has 38 changes in Chaos.cpp.

Would you like me to post the source for 11.067?
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Bit »

Poff. Think we need some water now ;)
Take a look at WinMerge Rasmus, that helps in such a case:
Track differences in two files and decide which piece to move whereto.
You will adjust the newer source pretty fast.
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Converting CSBWin graphicengine to a OpenGL 3D engine

Post by Rasmus »

Hehe, look at that, I hit my self on the fingers.. I was using the source for 11.014

Well, that was a couple of hours going down the drain.. Anyway, it was good codetraining :)
Post Reply

Return to “Chaos Strikes Back for Windows & Linux (CSBWin) / CSBuild”