[chocolate-doom] 11/42: Add mapping code to map out structures and switch thing/frame code to use this.

Jonathan Dowland jmtd at moszumanska.debian.org
Mon Jan 30 15:06:50 UTC 2017


This is an automated email from the git hooks/post-receive script.

jmtd pushed a commit to annotated tag chocolate-doom-0.1.0
in repository chocolate-doom.

commit aff12461949e9ffc29faed9f238c9a74412be2fa
Author: Simon Howard <fraggle at gmail.com>
Date:   Mon Oct 3 10:25:37 2005 +0000

    Add mapping code to map out structures and switch thing/frame code to use
    this.
    
    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 155
---
 src/Makefile.am   |   2 +-
 src/deh_frame.c   |  50 +++++++--------------
 src/deh_mapping.c |  95 +++++++++++++++++++++++++++++++++++++++
 src/deh_mapping.h |  89 ++++++++++++++++++++++++++++++++++++
 src/deh_thing.c   | 132 ++++++++++++++----------------------------------------
 5 files changed, 235 insertions(+), 133 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index de6bdac..ab7a702 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,7 +29,7 @@ dstrings.c  i_sound.h   p_ceilng.c  p_spec.h    r_sky.h     z_zone.h	\
 dstrings.h  i_system.c  p_doors.c   p_switch.c  r_state.h   mmus2mid.c  \
 d_textur.h  i_system.h  p_enemy.c   p_telept.c  r_things.c  mmus2mid.h  \
 deh_defs.h  deh_frame.c deh_main.c  deh_ptr.c   deh_text.c  deh_thing.c \
-deh_io.c    deh_io.h    deh_ammo.c  deh_weapon.c
+deh_io.c    deh_io.h    deh_ammo.c  deh_weapon.c deh_mapping.c deh_mapping.h
 
 
 if HAVE_WINDRES
diff --git a/src/deh_frame.c b/src/deh_frame.c
index dc528bb..4cf7eef 100644
--- a/src/deh_frame.c
+++ b/src/deh_frame.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_frame.c 154 2005-10-03 00:42:45Z fraggle $
+// $Id: deh_frame.c 155 2005-10-03 10:25:37Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,10 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2005/10/03 10:25:37  fraggle
+// Add mapping code to map out structures and switch thing/frame code to use
+// this.
+//
 // Revision 1.2  2005/10/03 00:42:45  fraggle
 // Frame numbers are indexed from 0
 //
@@ -42,6 +46,16 @@
 
 #include "deh_defs.h"
 #include "deh_main.h"
+#include "deh_mapping.h"
+
+DEH_BEGIN_MAPPING(state_mapping, state_t)
+  DEH_MAPPING("Sprite number",    sprite)
+  DEH_MAPPING("Sprite subnumber", frame)
+  DEH_MAPPING("Duration",         tics)
+  DEH_MAPPING("Next frame",       nextstate)
+  DEH_MAPPING("Unknown 1",        misc1)
+  DEH_MAPPING("Unknown 2",        misc2)
+DEH_END_MAPPING
 
 static void *DEH_FrameStart(deh_context_t *context, char *line)
 {
@@ -90,39 +104,7 @@ static void DEH_FrameParseLine(deh_context_t *context, char *line, void *tag)
     
     // set the appropriate field
 
-    if (!strcasecmp(variable_name, "Sprite number"))
-    {
-        state->sprite = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Sprite subnumber"))
-    {
-        state->frame = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Duration"))
-    {
-        state->tics = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Next frame"))
-    {
-        state->nextstate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Codep Frame"))
-    {
-        // FIXME: code pointer
-    }
-    else if (!strcasecmp(variable_name, "Unknown 1"))
-    {
-        state->misc1 = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Unknown 2"))
-    {
-        state->misc2 = ivalue;
-    }
-    else
-    {
-        printf("Unknown variable name %s\n", variable_name);
-    }
-
+    DEH_SetMapping(&state_mapping, state, variable_name, ivalue);
 }
 
 deh_section_t deh_section_frame =
diff --git a/src/deh_mapping.c b/src/deh_mapping.c
new file mode 100644
index 0000000..fa19f8e
--- /dev/null
+++ b/src/deh_mapping.c
@@ -0,0 +1,95 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id: deh_mapping.c 155 2005-10-03 10:25:37Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1  2005/10/03 10:25:37  fraggle
+// Add mapping code to map out structures and switch thing/frame code to use
+// this.
+//
+//
+//-----------------------------------------------------------------------------
+//
+// Dehacked "mapping" code
+// Allows the fields in structures to be mapped out and accessed by
+// name
+//
+//-----------------------------------------------------------------------------
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "deh_mapping.h"
+
+//
+// Set the value of a particular field in a structure by name
+//
+
+boolean DEH_SetMapping(deh_mapping_t *mapping, 
+                       void *structptr, char *name, int value)
+{
+    int i;
+
+    for (i=0; mapping->entries[i].name != NULL; ++i)
+    {
+        deh_mapping_entry_t *entry = &mapping->entries[i];
+
+        if (!strcasecmp(entry->name, name))
+        {
+            void *location;
+
+            location = structptr + (entry->location - mapping->base);
+
+     //       printf("Setting %p::%s to %i (%i bytes)\n",
+     //               structptr, name, value, entry->size);
+                
+            switch (entry->size)
+            {
+                case 1:
+                    * ((unsigned char *) location) = value;
+                    break;
+                case 2:
+                    * ((unsigned short *) location) = value;
+                    break;
+                case 4:
+                    * ((unsigned int *) location) = value;
+                    break;
+                case 8:
+                    * ((unsigned long long *) location) = value;
+                    break;
+                default:
+                    fprintf(stderr, "DEH_SetMapping: Unknown field type for %s\n", name);
+                    return false;
+            }
+
+            return true;
+        }
+    }
+
+    // field with this name not found
+
+    fprintf(stderr, "DEH_SetMapping: field named '%s' not found\n",
+            name);
+
+    return false;
+}
+
diff --git a/src/deh_mapping.h b/src/deh_mapping.h
new file mode 100644
index 0000000..d390bbb
--- /dev/null
+++ b/src/deh_mapping.h
@@ -0,0 +1,89 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id: deh_mapping.h 155 2005-10-03 10:25:37Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1  2005/10/03 10:25:37  fraggle
+// Add mapping code to map out structures and switch thing/frame code to use
+// this.
+//
+//
+//-----------------------------------------------------------------------------
+//
+// Dehacked "mapping" code
+// Allows the fields in structures to be mapped out and accessed by
+// name
+//
+//-----------------------------------------------------------------------------
+
+#ifndef DEH_MAPPING_H
+#define DEH_MAPPING_H
+
+#include "doomtype.h"
+
+#define DEH_BEGIN_MAPPING(mapping_name, structname)           \
+    static structname deh_mapping_base;                       \
+    static deh_mapping_t mapping_name =                       \
+    {                                                         \
+        &deh_mapping_base,                                    \
+        {
+
+#define DEH_MAPPING(deh_name, fieldname)                      \
+             {deh_name, &deh_mapping_base.fieldname,          \
+                 sizeof(deh_mapping_base.fieldname)},
+            
+#define DEH_END_MAPPING                                       \
+             {NULL}                                           \
+        }                                                     \
+    };
+
+    
+
+#define MAX_MAPPING_ENTRIES 32
+
+typedef struct deh_mapping_s deh_mapping_t;
+typedef struct deh_mapping_entry_s deh_mapping_entry_t;
+
+struct deh_mapping_entry_s 
+{
+    // field name
+   
+    char *name;
+
+    // location relative to the base in the deh_mapping_t struct
+
+    void *location;
+
+    // field size
+
+    int size;
+};
+
+struct deh_mapping_s
+{
+    void *base;
+    deh_mapping_entry_t entries[MAX_MAPPING_ENTRIES];
+};
+
+boolean DEH_SetMapping(deh_mapping_t *mapping, void *structptr, char *name, int value);
+
+#endif /* #ifndef DEH_MAPPING_H */
+
diff --git a/src/deh_thing.c b/src/deh_thing.c
index f4c79f6..4f4d675 100644
--- a/src/deh_thing.c
+++ b/src/deh_thing.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_thing.c 153 2005-10-02 23:49:01Z fraggle $
+// $Id: deh_thing.c 155 2005-10-03 10:25:37Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,10 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.2  2005/10/03 10:25:37  fraggle
+// Add mapping code to map out structures and switch thing/frame code to use
+// this.
+//
 // Revision 1.1  2005/10/02 23:49:01  fraggle
 // The beginnings of dehacked support
 //
@@ -38,9 +42,36 @@
 
 #include "deh_defs.h"
 #include "deh_main.h"
+#include "deh_mapping.h"
 
 #include "info.h"
 
+DEH_BEGIN_MAPPING(thing_mapping, mobjinfo_t)
+  DEH_MAPPING("ID #",                doomednum)
+  DEH_MAPPING("Initial frame",       spawnstate)
+  DEH_MAPPING("Hit points",          spawnhealth)
+  DEH_MAPPING("First moving frame",  seestate)
+  DEH_MAPPING("Alert sound",         seesound)
+  DEH_MAPPING("Reaction time",       reactiontime)
+  DEH_MAPPING("Attack sound",        attacksound)
+  DEH_MAPPING("Injury frame",        painstate)
+  DEH_MAPPING("Pain chance",         painchance)
+  DEH_MAPPING("Pain sound",          painsound)
+  DEH_MAPPING("Close attack frame",  meleestate)
+  DEH_MAPPING("Far attack frame",    missilestate)
+  DEH_MAPPING("Death frame",         deathstate)
+  DEH_MAPPING("Exploding frame",     xdeathstate)
+  DEH_MAPPING("Death sound",         deathsound)
+  DEH_MAPPING("Speed",               speed)
+  DEH_MAPPING("Width",               radius)
+  DEH_MAPPING("Height",              height)
+  DEH_MAPPING("Mass",                mass)
+  DEH_MAPPING("Missile damage",      damage)
+  DEH_MAPPING("Action sound",        activesound)
+  DEH_MAPPING("Bits",                flags)
+  DEH_MAPPING("Respawn frame",       raisestate)
+DEH_END_MAPPING
+
 static void *DEH_ThingStart(deh_context_t *context, char *line)
 {
     int thing_number = 0;
@@ -89,104 +120,9 @@ static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag)
 
     ivalue = atoi(value);
     
-    // set the appropriate field
+    // Set the field value
 
-    if (!strcasecmp(variable_name, "ID #"))
-    {
-        mobj->doomednum = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Initial frame"))
-    {
-        mobj->spawnstate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Hit points"))
-    {
-        mobj->spawnhealth = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "First moving frame"))
-    {
-        mobj->seestate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Alert sound"))
-    {
-        mobj->seesound = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Reaction time"))
-    {
-        mobj->reactiontime = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Attack sound"))
-    {
-        mobj->attacksound = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Injury frame"))
-    {
-        mobj->painstate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Pain chance"))
-    {
-        mobj->painchance = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Pain sound"))
-    {
-        mobj->painsound = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Close attack frame"))
-    {
-        mobj->meleestate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Far attack frame"))
-    {
-        mobj->missilestate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Death frame"))
-    {
-        mobj->deathstate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Exploding frame"))
-    {
-        mobj->xdeathstate = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Death sound"))
-    {
-        mobj->deathsound = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Speed"))
-    {
-        mobj->speed = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Width"))
-    {
-        mobj->radius = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Height"))
-    {
-        mobj->height = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Mass"))
-    {
-        mobj->mass = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Missile damage"))
-    {
-        mobj->damage = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Action sound"))
-    {
-        mobj->activesound = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Bits"))
-    {
-        mobj->flags = ivalue;
-    }
-    else if (!strcasecmp(variable_name, "Respawn frame"))
-    {
-        mobj->raisestate = ivalue;
-    }
-    else
-    {
-        printf("Unknown variable name %s\n", variable_name);
-    }
+    DEH_SetMapping(&thing_mapping, mobj, variable_name, ivalue);
 }
 
 deh_section_t deh_section_thing =

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/chocolate-doom.git



More information about the Pkg-games-commits mailing list