Author Topic: PHP PMS Read and Render - !!!! Realeased !!!!  (Read 8368 times)

0 Members and 1 Guest are viewing this topic.

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
PHP PMS Read and Render - !!!! Realeased !!!!
« on: May 12, 2007, 08:06:11 pm »
PHP PMS Map Renderer v4
Fully written by Doc


What
This script will read a PMS map and output all of its data.
It can render a image of the PMS map with polygons, spawn points, colliders and waypoints.

If Image rendering options are set to 0 then you can use the normal textual data of teh map like title weather number of polygons and more.


Important
This script is under GPL. You may use this and/or edit lines, but MUST keep the copy right string visible in generated images.


The explanation is written in the readme.txt on how to use this.


There is about 600 lines so I did not post it here. (Tell me if 700 lines will fit here)
So I uploaded it to my site: Download


Fot those that just want a simple reader that gets you like the title and weather and stuff here is the code:
Code: [Select]
<?php
// Textual PHP PMS Data Reader 
// Version 4
// Fully written by: Mikhail D.
// AKA: Doc
// Date: May 12, 2007

class mapInfo {

// Constructor.
function mapInfo($path

$this->path $path;
$this->read($this->path);
}

// Reader.
function read($path)
{
$file fopen($path"rb");
$bin fread($filefilesize($path));
$hex bin2hex($bin);
fclose($file);
$pos 0;

$pos += 4// header

$title_length  hexdec(bin2hex(substr($bin,$pos,1))); // title len
$pos += 1;

$this->title $this->hexstr(bin2hex(substr($bin,$pos,$title_length))); // title
$pos += 38;

$texture_length  hexdec(bin2hex(substr($bin,$pos,1))); // texture len
$pos += 1;

$this->texture $this->hexstr(bin2hex(substr($bin,$pos,$texture_length))); // texture
$pos += 24;

$this->color_top "#".bin2hex(substr($bin,$pos,3)); // color top
$pos += 4;

$this->color_bottom  "#".bin2hex(substr($bin,$pos,3)); // color low
$pos += 4;

$this->jets $this->num2jets($this->bin2long(substr($bin,$pos,4))); // jets
$pos += 4;

$this->grenades hexdec(bin2hex(substr($bin,$pos,1))); // grenades
$pos += 1;

$this->medkits hexdec(bin2hex(substr($bin,$pos,1))); // medics
$pos += 1;

$this->weather $this->num2weather(hexdec(bin2hex(substr($bin,$pos,1)))); // weather
$pos += 1;

$this->steptype $this->num2steptype(hexdec(bin2hex(substr($bin,$pos,1)))); // step type
$pos += 1;

$pos += 4// ID

$this->poly_count $this->bin2long(substr($bin,$pos,4)); // poly count
$pos += 4;

$pos += 121 $this->poly_count// pass all polygons

$pos += 4// sector division

$sector_count $this->bin2long(substr($bin,$pos,4)); // sector count
$sector_count = (($sector_count*2)+1)*(($sector_count*2)+1);
$pos += 4;

// sector len skip start
$pos2 $pos 2;
for ( $i 1$i <= $sector_count$i += 1)
{
$dec2 hexdec(substr($hex,$pos2,2));
if($dec2 0){ $pos2 += (4*$dec2); }
$pos2 += 4
}
$pos $pos2 2;
// sector len skip end

$prop_count $this->bin2long(substr($bin,$pos,4)); // prop count
$pos += 4

$pos += $prop_count 44// passing prop data

$this->scenery_count $this->bin2long(substr($bin,$pos,4)); // scenery count
$pos += 4;

if($this->scenery_count 0// scenery list if any
$this->sceneryList(substr($bin,$pos,55 $this->scenery_count));

$pos += 55 $this->scenery_count// passing all scenery data

$this->collider_count $this->bin2long(substr($bin,$pos,4)); // collider count
$pos += 4

$pos += 16 $this->collider_count// passing all collider data

$this->spawnpoint_count $this->bin2long(substr($bin,$pos,4)); // spawnpoint count
$pos += 4;

$pos += 16 $this->spawnpoint_count// passing all spawnpoint data

$this->waypoint_count $this->bin2long(substr($bin,$pos,4)); // waypoint count
$pos += 4;

}

function sceneryList($scenery_bin) {
$this->scenery_list = array();
$p 0;
for ( $i 1$i <= $this->scenery_count$i++)
{
$scenery_hex bin2hex(substr($scenery_bin,$p,55));
$scenery_length hexdec(substr($scenery_hex,0,2));
$this->scenery_list[$i][0] = $this->hexstr(substr($scenery_hex,2,$scenery_length*2)); // name
$this->scenery_list[$i][1] = substr($scenery_hex,102,4); // x
$this->scenery_list[$i][2] = substr($scenery_hex,106,4); // y
$p += 55;
}
}

// Converters pass this point.

function num2steptype($steptype) {
if($steptype == "00")
$steptype "Hard Ground";
elseif($steptype == "01")
$steptype "Soft Ground";
elseif($steptype == "02")
$steptype "None";
else
$steptype "Error: Invalid step type in map.";
return $steptype;
}

function num2weather($weather) {
if($weather == "00")
$weather "Normal";
elseif($weather == "01")
$weather "Rain";
elseif($weather == "02")
$weather "Sand Storm";
elseif($weather == "03")
$weather "Snow";
else
$weather "Error: Invalid weather in map.";
return $weather;
}

function num2jets($jets) {
if($jets == 0)
$jets "None (".$jets.")";
elseif($jets == 12)
$jets "Minimal (".$jets.")";
elseif($jets == 45)
$jets "Very Low (".$jets.")";
elseif($jets == 95)
$jets "Low (".$jets.")";
elseif($jets == 190)
$jets "Normal (".$jets.")";
elseif($jets == 320)
$jets "Lots (".$jets.")";
elseif($jets == 800)
$jets "Maximum (".$jets.")";
else
$jets "Custom (".$jets.")";
return $jets;
}

function bin2long($bin) {
if(strlen($bin) == 4)
$long unpack("l"$bin);
else
$long = array(=> 0);
return $long[1];
}

function hexstr($hexstr) {
$hexstr str_replace(' '''$hexstr);
$retstr pack('H*'$hexstr);
return $retstr;
}

}

// how to use
$map = new mapInfo("ctf_Ash.PMS");
echo 
$map->title."<br>";
echo 
$map->texture."<br>";
echo 
$map->color_top."<br>";
echo 
$map->color_bottom."<br>";
echo 
$map->jets."<br>";
echo 
$map->grenades."<br>";
echo 
$map->medkits."<br>";
echo 
$map->weather."<br>";
echo 
$map->steptype."<br>";
echo 
$map->poly_count."<br>";
echo 
$map->scenery_count."<br>";
for(
$i 1$i <= $map->scenery_count$i++)
{
echo $map->scenery_list[$i][0]."<br>";
}
echo 
$map->collider_count."<br>";
echo 
$map->spawnpoint_count."<br>";
echo 
$map->waypoint_count."<br>";

?>
Those are the only things tha it will out put!

Version 4
- rewritten the whole code in class.
- modified, graphical objects loaded from image.
- added, easy otions and structure
- added, a lot of small things and stuff.

Version 3
- modified, orginized script to better performance
- modified, graphical objects simplified.

Version 2
- added, generating graphical spawns

Version 1
- basic read


Any questions or sugestion?
« Last Edit: October 12, 2008, 03:03:02 am by jrgp »

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PHP PMS Read and Render
« Reply #1 on: May 12, 2007, 08:09:01 pm »
My sugestion: keep going, you made a cool job there ;)
urraka

Offline mar77a

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1295
  • mad
    • random stuffs
Re: PHP PMS Read and Render
« Reply #2 on: May 12, 2007, 08:28:31 pm »
teh selfish

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: PHP PMS Read and Render
« Reply #3 on: May 12, 2007, 11:36:14 pm »
teh just give us the PHP script kthx

Offline DePhille

  • Flagrunner
  • ****
  • Posts: 623
  • SoldatPage Webmaster
    • SoldatPage
Re: PHP PMS Read and Render
« Reply #4 on: May 13, 2007, 04:00:37 am »
Indeed, many people are looking for this, including me.
I can't see a valid reason why you wouldn't release the code. Some day or another, someone else will have the time and patience to write the same code and release it. Then he'll get more appreciation than you do, even if you found it first and yours is better than his.

The script is a good job, I know how it works. It's just stupid to write the script, knowing that someone else already did. I'd take away your work if I made it and published the code, so I'm leaving the publishing part up to you ;).

Grtz, DePhille
This signature was broken. Feel free to fix it.

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
Re: PHP PMS Read and Render
« Reply #5 on: May 13, 2007, 04:45:23 pm »
yeah I gues i should show the script.

Give me 1 or 2 days to referbish it. And write a "how to work it" thing and ill post it.



ps: after ill put in scenery option, i'll get to work on gradient triangle math (I started it befor but never got around to continue it. just needs time to outomate teh same lines.)
« Last Edit: May 13, 2007, 04:51:45 pm by Doc »

Offline DePhille

  • Flagrunner
  • ****
  • Posts: 623
  • SoldatPage Webmaster
    • SoldatPage
Re: PHP PMS Read and Render (to be released)
« Reply #6 on: May 14, 2007, 10:23:53 am »
Ahh, thanks.
We'll post suggestions once we have any.

Grtz, DePhille
This signature was broken. Feel free to fix it.

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #7 on: May 14, 2007, 08:25:43 pm »
I have released now. Please do read teh reasme.txt it will show you how to use it.
http://soldat.planets.gamespy.com/Files-view.php?f=php_pms_map_renderer_4.zip

Offline rainrider

  • Soldier
  • **
  • Posts: 145
    • rrhp
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #8 on: May 15, 2007, 01:58:30 am »
LOL and u want to add teh triangle-transformed textures dear imagefilledpolygon user : D

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #9 on: May 15, 2007, 02:40:33 am »
what are you talking about?

I can fill polygons wiht textures simple adding 2 lines and a small modification to the imagefunction

<snip> long off topic flame; keep it on topic, and keep with the rules of the forum --Chrisgbk</snip>

That what happands when i feel like i got a rude comment in 3:40 am.
« Last Edit: May 15, 2007, 03:03:10 am by chrisgbk »

Offline rainrider

  • Soldier
  • **
  • Posts: 145
    • rrhp
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #10 on: May 15, 2007, 08:47:04 am »
You just didn't show any custom image function in your code yet. That's why I laughed.

Also, polygon textures are stretched, rotated, deformed. You can't just load them and then create mask or something.

Even if you write your own pixel shader, it will be way too slow. Why?
Because you need to use many variables like pixel rgba, x, y, theta etc etc which need too be reparsed many times.
Because PHP is scripting language, you can't compile scripts; php script will always work way slower than compiled program.
Because imagefilledpolygon is placed in compiled library and it uses easy floodfill while you need to write your own function which will process large texture files, colorize them and furthermore set it's alpha.

If I were you, I'd write console program which would use OpenGL. OpenGL is well-optimized and it uses directly graphic card processor. That program would just draw everything and output screen in any format (even in your own), and you could run it in php script using system() (and if you'd use your own file format - load output file, set pixels [it will be always faster than slow processing all polys] and use imagepng or sth).

I don't want to be presuming or sth, I want to give you few advices.

@low:
ehh..
Quote from: Doc
Any questions or sugestion?
Quote from: EnEsCe
gj with flippin burgers
« Last Edit: May 15, 2007, 11:31:29 am by rainrider »

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #11 on: May 15, 2007, 10:14:41 am »
Are you blind or just came out from under a rock?

This is for just displaying an image on a website.

IF YOU DONT LIKE THE IMAGE GENERATOR PART THEN JUST DONT SELECT IT AND USE THE NORMAL DATA THAT IS IN THE PMS.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #12 on: May 15, 2007, 01:07:55 pm »
Using system() or anything like that would be a really bad idea, cuz the good thing about this script is that it can be run on any website with php support.
urraka

Offline rainrider

  • Soldier
  • **
  • Posts: 145
    • rrhp
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #13 on: May 15, 2007, 03:05:33 pm »
If you have enough money to buy host offering such webspace to share so many maps and its screens, no matters if it uses system() or not, you know what I mean.

Anyway you can always just download all maps at end of every day, then run rendering prog and just upload output screens. You can also write some program which would do everything automatically.
« Last Edit: May 15, 2007, 03:09:35 pm by rainrider »

Offline blackdevil0742

  • Veteran
  • *****
  • Posts: 1061
  • Don't Panic
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #14 on: May 15, 2007, 03:41:09 pm »
teh selfish
..and you're not? *cough* your server *cough*

Um yeah. Good job on this.

OBEY!!!

Offline mar77a

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1295
  • mad
    • random stuffs
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #15 on: May 15, 2007, 04:23:19 pm »
what server? o-o

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #16 on: May 16, 2007, 02:12:12 pm »
I alwasy did despise mar77a.  :P

Offline Thomas

  • Major
  • *
  • Posts: 76
    • mnus.de
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #17 on: May 17, 2007, 02:00:41 pm »
nice work!
i wanted to do it a few days ago, but you've been faster

Offline Doc

  • Soldier
  • **
  • Posts: 128
    • Soldat Files Directory
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #18 on: May 17, 2007, 04:23:25 pm »
I made teh scrip like in early 2006 you know.

And just know I made it public :p

Offline Coolio

  • Camper
  • ***
  • Posts: 320
  • Well cya all.
Re: PHP PMS Read and Render - !!!! Realeased !!!!
« Reply #19 on: May 20, 2007, 03:49:35 pm »
Nice, Thank You!!!
BANNED