Z Coordinates ...

Discussions on various DOL development features

Moderator: Support Team

Re: Z Coordinates ...

Postby Nydirac » Thu Aug 20, 2015 9:52 am

Not so sure, to make it feasible ( you can't really expect someone to put 4,5Gb of the client on a server for 20-30mb of data, think of the vps /etc.... ) it should be only the files needed, so a process of extracting the offset/terrain files (pcx files) is needed before giving them to the server... and then it could be said you're using client files...

Sorry for the rambling/rushing/confusing text, i'm writing at work lol
User avatar
Nydirac
Inactive Staff Member
 
Posts: 31
Joined: Sun Sep 21, 2003 6:11 pm
Website: http://www.promiseshard.com/

Re: Z Coordinates ...

Postby Leodagan » Sat Aug 22, 2015 9:19 am

Maybe we can just use a "subset" of the needed MPK files (leaving texture/sound and other ressources), it should be easy to provide a script to run a "xcopy" or a "find -exec" that would filter the needed files to prevent copying the full client directory.

And user that still want to copy the full client will have the needed files at the right place anyway :)
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: Z Coordinates ...

Postby Merec » Sun Aug 23, 2015 8:22 pm

I would love to help implementing this if you want. I spent hours of getting into the whole map creation thing. My MapCreator creates pre rendered heightmaps where you can get the heightvalue very easy. I prerendered all zones, which result in 132 files with just 9 MB.

A bonus feature can be, that I can add all trees and other simple objects with their z-value on the surface. Contact me if interested.
Merec
Developer
 
Posts: 428
Joined: Thu Mar 08, 2007 8:58 am
Website: http://www.merec.org
Location: NRW, Germany

Re: Z Coordinates ...

Postby Leodagan » Mon Aug 24, 2015 5:31 am

If I remember :

Trees are listed in some file with their X/Y Coordinate, and a Radius, No height :)

They are just cylinder (that have no limit Bottom/Top ?) used for Collision...

And this way they are "easy" to import, but not really easy to use for "Collision" detection, we need some good algorithm to use with this data (binary space partitioning tree etc...)

Do you know if the MPK library included in DOL Server (DOLBase/MPK/*) can be used to import heightmaps ?

Or maybe it's deprecated ?
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: Z Coordinates ...

Postby Merec » Mon Aug 24, 2015 7:48 am

The mpk lib is only required to get the files (pcx, csv) from the mpk-files in the zone directories. I am using the version from DOL, so its still working. To get the height value, there is some kind of image processing required. I don't know if C# is able to do this out of the box, I m using Magick.NET, a .NET wrapper for ImageMagick.

I am able to get the height values of objects like trees and put them on the prerendered image.
Merec
Developer
 
Posts: 428
Joined: Thu Mar 08, 2007 8:58 am
Website: http://www.merec.org
Location: NRW, Germany

Re: Z Coordinates ...

Postby Leodagan » Mon Aug 24, 2015 12:51 pm

Last time we studied the "image processing" needed it was a dumb "bilinear filtering"

You need a good half-day to code this from zero :D you should find plenty of "managed" code library to do it for you ;)
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: Z Coordinates ...

Postby Nydirac » Tue Aug 25, 2015 7:26 am

Last time we studied the "image processing" needed it was a dumb "bilinear filtering"

You need a good half-day to code this from zero :D you should find plenty of "managed" code library to do it for you ;)
Code: Select all
System.Drawing.Bitmap m_bmp = DevIL.DevIL.LoadBitmap(path); for (int y = 0; y < 255; y++) { for (int x = 0; x < 255; x++) { ValueOffset[x, y] = m_bmp.GetPixel(x, y).R; } }
Here you go! It's the dumbest and simplest thing in the world, no need for anything else ;)
Same to do for the terrain data, and you need the zones info!

Anyway when i have 2-3 hours to do the things properly i will give you guys the complete code, it's pretty simple to be honest but it has to be really optimized and bug free if you want to use it for all...
User avatar
Nydirac
Inactive Staff Member
 
Posts: 31
Joined: Sun Sep 21, 2003 6:11 pm
Website: http://www.promiseshard.com/

Re: Z Coordinates ...

Postby Leodagan » Tue Aug 25, 2015 8:14 am

There is no interpolation in your code snippet :p
User avatar
Leodagan
Developer
 
Posts: 1350
Joined: Tue May 01, 2012 9:30 am
Website: https://daoc.freyad.net
Location: Lyon

Re: Z Coordinates ...

Postby Graveen » Thu Aug 27, 2015 9:32 am

Merec, possible a tool for autoextraction of height maps so it can be generated independently of the client version ? 10mb files is not really a problem, so the bitmap can even be cached, although i guess it should be in plain bmp in memory so take a lot on more space.

The interpolation can be either done on generation (final usable height map) or on the fly in first time.
/salute !
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Z Coordinates ...

Postby Maze » Sun Apr 10, 2016 12:31 am

Anyone have contact with Nydirac? I'm interested in his data and implementation.
User avatar
Maze
DOL Apprentice
 
Posts: 38
Joined: Wed Aug 08, 2012 3:39 am

Re: Z Coordinates ...

Postby Dunnerholl » Thu Apr 28, 2016 12:58 am

10 years after the OP and still no solution? :D
Dunnerholl
Developer
 
Posts: 1229
Joined: Mon Sep 08, 2008 8:39 pm

Re: Z Coordinates ...

Postby Dinberg » Thu Apr 28, 2016 6:12 pm

Still waiting for you old bud :)
The Marvelous Contraption begins to stir...
User avatar
Dinberg
Inactive Staff Member
 
Posts: 4695
Joined: Sat Mar 10, 2007 9:47 am
Yahoo Messenger: dinberg_darktouch
Location: Jordheim

Re: Z Coordinates ...

Postby Dunnerholl » Sun May 01, 2016 6:02 pm

Still waiting for you old bud :)
i'm plaing on ywain at times. they still have lots of their own problems with pathing, pet los, and all
Dunnerholl
Developer
 
Posts: 1229
Joined: Mon Sep 08, 2008 8:39 pm

Re: Z Coordinates ...

Postby Graveen » Mon May 02, 2016 7:41 am

I'm also playing on hib side ! PST me :)
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Z Coordinates ...

Postby Nydirac » Wed Nov 09, 2016 3:08 pm

Ok i'm going to be blunt: I completely forgot about this (i honestly thought i already submitted the relevant parts... but meh...) and i'm not going to check grammar/etc on this. (because i'm lazy... sue me)

So here we go with all the code needed to calculate the Z.

First thing: You need the appropriate files! Fortunately for us all the infos are in the client (i don't know if there are copyright issues or something, they could be parsed in matrixes and but on the database to remove this issue... nothing difficult to do)
The file needed are in the zones directory on the client, inside each datXXX.mpk files.

I have provided the soruce code of my parser as
MPKExtractor.7z
Parser for the files needed
(50.21 KiB) Downloaded 36 times
: the input is the folder zones inside the daoc installation (it target the zones.mpk for semplicity) the result is a ServerData directory to put on the gameserver main directory.
Someone with the permission to modify the repo should correct a little problem with your MPK.cs file, the correct way to parse the header is NOT your
Code: Select all
m_crc.Value = (long)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); m_sizeDir = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]); m_sizeName = ((buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11]); m_numFiles = ((buf[12] << 24) | (buf[13] << 16) | (buf[14] << 8) | buf[15]);
but
Code: Select all
m_crc.Value = (long)((buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]); m_sizeDir = ((buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4]); m_sizeName = ((buf[11] << 24) | (buf[10] << 16) | (buf[9] << 8) | buf[8]); m_numFiles = ((buf[15] << 24) | (buf[14] << 16) | (buf[13] << 8) | buf[12]);
The parser uses the FileDialog so it need the assembly System.Windows.Forms (even if its a console program... ops?) so you're welcome to give the zones directory by argument if you want to remove it, no big deal.

Second thing: The code for the system, i'm not updated on the current style situation so i have put where i found it more appropriate (i might be wrong... you're welcome to refine it).

The files of the terrain are in PCX format and i haven't found a simple .net wrapper for it so i created a simple parser which will convert the pcx file to a bitmap objects, put the
PCXFile.cs
From PCX File to bitmap object
(3.19 KiB) Downloaded 34 times
somewhere on the gameserver/dolserver project AND add the System.Drawing assembly!

The code for calculating the Z, put it on the Zone.cs file (i put it after the last region...)
Code: Select all
#region Z private bool m_zActive = false; public bool zActive { get { return m_zActive; } } private byte[,] m_zoneTerrain; private byte[,] m_zoneOffset; private byte m_scalefactor; private byte m_offsetfactor; public int getZ(int X, int Y) { if (!m_zActive || m_zoneTerrain == null || m_zoneOffset == null) return 0; // In case of error you COULD return -1 and handle all the problems... try { int x = X - XOffset; // EDIT: Sorry, forgot to restore after fix int y = Y - YOffset; if (x < 0 || x > 65535 || y < 0 || y > 65535) { //log.Error(string.Format("ZMgr: Value either too big or too low! X:{0} Y:{1} ZoneID:{2}", x, y, ZoneID)); return 0; } int sx = x >> 8; int sy = y >> 8; double ox = x / 256.0f - sx; double oy = y / 256.0f - sy; if (ox + oy < 1) //Check the position of the point: we are going to use math to convert a 256x256 matrix to a 65kx65k! yay math! { //Top triangle int h_xy = getZonePointHeight(sx, sy); int h_x1y = getZonePointHeight(sx + 1, sy); int h_xy1 = getZonePointHeight(sx, sy + 1); return (int)(h_xy + (h_x1y - h_xy) * ox + (h_xy1 - h_xy) * oy); } else { //Bottom triangle int h_x1y = getZonePointHeight(sx + 1, sy); int h_xy1 = getZonePointHeight(sx, sy + 1); int h_x1y1 = getZonePointHeight(sx + 1, sy + 1); return (int)(h_x1y1 + (h_xy1 - h_x1y1) * (1.0 - ox) + (h_x1y - h_x1y1) * (1.0 - oy)); } } catch (Exception ex) { //DOL.Promise.Mail.SendMail("nydirac@gmail.com", "Z Exception", ex.Message + " ---------> " + ex.StackTrace); return 0; } } private int getZonePointHeight(int X, int Y) //Raw data from the terrain data { if (X > 255 || X < 0 || Y > 255 || Y < 0) // In case of freak accident, better to be safe than sorry... { //log.Warn("GetZonePointHeight error! X: " + X + " Y: " + Y + " ZoneID: " + ZoneID); return 0; } return (m_zoneTerrain[X,Y] * m_scalefactor + m_zoneOffset[X, Y] * m_offsetfactor); } #endregion
and last the GM' script to check if it actually work, just use /getz and it will give you the calculated Z of the selected object/living/whatever (or if you're not selecting something... the z of your character).


Now.... its pretty useless if you don't implement for it, on Promise Shard (late 2005) i used it to pretty much doing anything... spawning monster on appropriate height (so it will calulate the CORRECT distance from players/etc) ... for calculating the correct Z of the walk script etc (no more mob under the terrain, yay!) and correct speed calulation of the mob with the angle of the terrain.


IT will NOT work on dungeons (because they're 3d maps and other things, i was implementing it but i lost all the files...


continues (next post)
Last edited by Nydirac on Wed Nov 09, 2016 6:09 pm, edited 4 times in total.
User avatar
Nydirac
Inactive Staff Member
 
Posts: 31
Joined: Sun Sep 21, 2003 6:11 pm
Website: http://www.promiseshard.com/


Return to “%s” DOL Development Discussion

Who is online

Users browsing this forum: No registered users and 1 guest