Jump to content

[9521][fix] Compilation of map and DBC extractor on Mac OSX


Recommended Posts

Posted

Fix for: This patch fixes the compilation of the map and dbc extractor on linux, allowing for Mac OSX users to build the extractor and extract the DBCs and maps, without need of access to linux or windows.

Version:

stupid-ul:mangos imbecile$ git log -r -1
commit c365a17a8f66a4a83b429ef6cb746d6f43afa9d6
Author: VladimirMangos <[email protected]>
Date:   Thu Mar 4 04:04:47 2010 +0300

   [9510] Gameobject casting improvements.

   * Add IsHostileTo/IsFriendlyTo and implement expected way checks for diff. world object types.
     For controlled object check redirected to specific owner, for wild gameobject base at gameobject faction.
     If faction not set expected to be hostile to anyone.
   * Update grid searchers to be usable with world object instead only unit case.
     Some grid searches lost redundent second object arg, AnyAoETargetUnitInObjectRangeCheck lost hitHidden arg
     (for hitHidden==true case added new AnyAoEVisibleTargetUnitInObjectRangeCheck)
   * Updated grid searchers used with gameobject area casts now.
     Note: Gameobject area spell cast animation will still wrong show around cast triggering target instead
     center around gameobject.
   * In case gameobject aura apply to target for restored use target itself as caster because
     we not have currently another way apply aura form wild gameobject.

Lighthouse reference: None

Devs: imbecile (my inaccessable alternate id on the forums)

Code: paste2.org URL

http://paste2.org/p/700261

diff --git a/contrib/extractor/libmpq/common.cpp b/contrib/extractor/libmpq/common.cpp
index 7b90208..9daf307 100644
--- a/contrib/extractor/libmpq/common.cpp
+++ b/contrib/extractor/libmpq/common.cpp
@@ -22,7 +22,7 @@
#define _CRT_SECURE_NO_DEPRECATE
//#include <dirent.h>
#include <sys/stat.h>
-//#include <unistd.h>
+#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -398,6 +398,8 @@ int libmpq_read_hashtable(mpq_archive *mpq_a) {

    #ifdef WIN32
        _lseeki64(mpq_a->fd, mpq_a->header->hashtablepos, SEEK_SET);
+    #elif defined(__APPLE__)
+        lseek(mpq_a->fd, mpq_a->header->hashtablepos, SEEK_SET);
    #else
        lseek64(mpq_a->fd, mpq_a->header->hashtablepos, SEEK_SET);
    #endif
@@ -457,6 +459,8 @@ int libmpq_read_blocktable(mpq_archive *mpq_a) {

    #ifdef WIN32
        _lseeki64(mpq_a->fd, mpq_a->header->blocktablepos, SEEK_SET);
+    #elif defined(__APPLE__)
+        lseek(mpq_a->fd, mpq_a->header->blocktablepos, SEEK_SET);
    #else
        lseek64(mpq_a->fd, mpq_a->header->blocktablepos, SEEK_SET);
    #endif    
@@ -521,6 +525,8 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo
        if (mpq_f->mpq_b->filepos != mpq_a->filepos) {
        #ifdef WIN32
            _lseeki64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
+        #elif defined(__APPLE__)
+            lseek(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
        #else
            lseek64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);

@@ -572,6 +578,8 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo

                #ifdef WIN32
                    _lseeki64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
+                #elif defined(__APPLE__)
+                    lseek(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
                #else
                    lseek64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
                #endif                
@@ -614,6 +622,8 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo

        #ifdef WIN32
            mpq_a->filepos = _lseeki64(mpq_a->fd, readpos, SEEK_SET);
+        #elif defined(__APPLE__)
+            mpq_a->filepos = lseek(mpq_a->fd, readpos, SEEK_SET);
        #else
            mpq_a->filepos = lseek64(mpq_a->fd, readpos, SEEK_SET);
        #endif    
diff --git a/contrib/extractor/libmpq/mpq.cpp b/contrib/extractor/libmpq/mpq.cpp
index e40f15d..be78a0e 100644
--- a/contrib/extractor/libmpq/mpq.cpp
+++ b/contrib/extractor/libmpq/mpq.cpp
@@ -78,6 +78,8 @@ int libmpq_archive_open(mpq_archive *mpq_a, unsigned char *mpq_filename) {
        mpq_a->header->id = 0;
        #ifdef WIN32
            _lseeki64(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
+        #elif defined(__APPLE__)
+            lseek(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
        #else
            lseek64(mpq_a->fd, mpq_a->mpqpos, SEEK_SET);
        #endif

Posted

rather than a function call, put in a macro definition, which will be faster. Something to the effect of

in <common.h>

#ifdef WIN32
   #define   libmpq_lseek _lseeki64
#elif defined(__APPLE__)
   #define  libmpq_lseek lseek
#else
   #define libmpq_lseek lseek64
#endif

and then usage:

libmpq_lseek(mpq_a->fd, pos, SEEK_SET);

Posted

It is not critical, but then it's about the mindset :)

Reason: This gives a small runtime speed boost (0.01%) to the extractor, along with

Patch against 9541

commit b156b0b4525cb9f406ba06a07f08c8716348c006
Author: pasdVn <[email protected]>
Date:   Sat Mar 6 22:20:03 2010 +0300

   [9541] Implement first target of spell 1064 and ranks boost from 61301.

   Signed-off-by: VladimirMangos <[email protected]>

Devs: imbecile

The patch is here

diff --git a/contrib/extractor/libmpq/common.cpp b/contrib/extractor/libmpq/common.cpp
index 8ce8646..e43a716 100644
--- a/contrib/extractor/libmpq/common.cpp
+++ b/contrib/extractor/libmpq/common.cpp
@@ -34,17 +34,6 @@
#include "common.h"
#include <ctype.h>

-unsigned int libmpq_lseek(mpq_archive* mpq_a, unsigned int pos)
-{
-#ifdef WIN32
-    return (unsigned int)_lseeki64(mpq_a->fd, pos, SEEK_SET);
-#elif defined(__APPLE__)
-    return (unsigned int)lseek(mpq_a->fd, pos, SEEK_SET);
-#else
-    return (unsigned int)lseek64(mpq_a->fd, pos, SEEK_SET);
-#endif
-}
-
/*
 *  This function decrypts a MPQ block.
 */
@@ -411,7 +400,7 @@ int libmpq_read_hashtable(mpq_archive *mpq_a) {
    /* Read the hash table into the buffer */
    bytes = mpq_a->header->hashtablesize * sizeof(mpq_hash);

-    libmpq_lseek(mpq_a, mpq_a->header->hashtablepos);
+    libmpq_lseek(mpq_a->fd, mpq_a->header->hashtablepos,SEEK_SET);

    rb = _read(mpq_a->fd, mpq_a->hashtable, bytes);
    if (rb != bytes) {
@@ -466,7 +455,7 @@ int libmpq_read_blocktable(mpq_archive *mpq_a) {
    bytes = mpq_a->header->blocktablesize * sizeof(mpq_block);
    memset(mpq_a->blocktable, 0, mpq_a->header->blocktablesize * sizeof(mpq_block));

-    libmpq_lseek(mpq_a, mpq_a->header->blocktablepos);
+    libmpq_lseek(mpq_a->fd, mpq_a->header->blocktablepos,SEEK_SET);

    rb = _read(mpq_a->fd, mpq_a->blocktable, bytes);
    if (rb != bytes) {
@@ -526,7 +515,7 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo
        unsigned int nread;

        if (mpq_f->mpq_b->filepos != mpq_a->filepos) {
-            libmpq_lseek(mpq_a, mpq_f->mpq_b->filepos);
+            libmpq_lseek(mpq_a->fd, mpq_f->mpq_b->filepos,SEEK_SET);
        }

        /* Read block positions from begin of file. */
@@ -571,7 +560,7 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo
            if (mpq_f->blockpos[0] != nread) {

                /* Try once again to detect file seed and decrypt the blocks */
-                libmpq_lseek(mpq_a, mpq_f->mpq_b->filepos);
+                libmpq_lseek(mpq_a->fd, mpq_f->mpq_b->filepos,SEEK_SET);

                nread = _read(mpq_a->fd, mpq_f->blockpos, (mpq_f->nblocks + 1) * sizeof(int));
                mpq_f->seed = libmpq_detect_fileseed(mpq_a, mpq_f->blockpos, nread);
@@ -608,7 +597,7 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo

    /* Set file pointer, if necessary. */
    if (mpq_a->filepos != readpos) {
-        mpq_a->filepos = libmpq_lseek(mpq_a, readpos);
+        mpq_a->filepos = libmpq_lseek(mpq_a->fd, readpos,SEEK_SET);
    }

    /* 15018F87 - Read all requested blocks. */
diff --git a/contrib/extractor/libmpq/common.h b/contrib/extractor/libmpq/common.h
index 57b34e9..c7a0cb6 100644
--- a/contrib/extractor/libmpq/common.h
+++ b/contrib/extractor/libmpq/common.h
@@ -71,4 +71,10 @@ int libmpq_conf_get_array(FILE *fp, char *search_value, char ***filelist, int *e
int libmpq_free_listfile(char **filelist);
int libmpq_read_listfile(mpq_archive *mpq_a, FILE *fp);

-unsigned int libmpq_lseek(mpq_archive* mpq_a, unsigned int pos);
+#ifdef WIN32
+    #define libmpq_lseek _lseeki64
+#elif defined(__APPLE__)
+    #define libmpq_lseek lseek
+#else
+    #define libmpq_lseek lseek64
+#endif
diff --git a/contrib/extractor/libmpq/mpq.cpp b/contrib/extractor/libmpq/mpq.cpp
index 9d60258..4c73983 100644
--- a/contrib/extractor/libmpq/mpq.cpp
+++ b/contrib/extractor/libmpq/mpq.cpp
@@ -77,7 +77,7 @@ int libmpq_archive_open(mpq_archive *mpq_a, unsigned char *mpq_filename) {
    while (!ncnt) {
        mpq_a->header->id = 0;

-        libmpq_lseek(mpq_a, mpq_a->mpqpos);
+        libmpq_lseek(mpq_a->fd, mpq_a->mpqpos,SEEK_SET);

        rb = _read(mpq_a->fd, mpq_a->header, sizeof(mpq_header));

Posted

Just add this little keyword called "inline" if you're soooo concerned about those 0.00....1% performance loss, instead of going back to stoneage with C Macros...

(in fact, i bet your compiler was inlining it anyway, gcc uses -finline-small-functions as early as O1...)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use