My xbox recommends II


It has been five days since I looked, and there are some changes, so let’s see what my Xbox recommends today. Games that were on the list last time are in italics.

I just noticed that it changed as I was writing this, so I probably won’t do this too often. No purchases from this list today, but not for any particular reasons.

 

Posted in Uncategorized | Tagged , , , | Leave a comment

Unexpected increment operator behavior – C# vs C++


I ran into an issue in my C#/XNA game, which turned out to be the ++ operator behaving in a way I didn’t expect (in conjunction with the assignment and new operators, in my case).

The basic problem is that I was constructing objects and adding them to an array; some objects could construct other objects and add them to the same array, within their own constructors.

This may not be the best idea 🙂 and I am certainly “fixing” it by simply rewriting it in a different way.

Here’s some sample source that exhibits the behavior. In C++, the array ends up with Buddy, Item, Buddy, Item. In C#, it contains Item, Buddy, Buddy, Item.

Hope this helps someone avoid the same thing – it was rather tricky to track down – the actual bug was a bit more complicated, but the root cause was the same.

C++ source

  #include <stdio.h>
  #include <tchar.h>

  const int MAX_PIECES = 5;

  class Piece {
  protected:
    wchar_t classname[100];
  };

  int pieceCount = 0;

  Piece *pieces[MAX_PIECES];

  class Item: public Piece {
  public:
    Item() {
      _stprintf(classname, L"Item");
      MakeBuddy();
    }
    void MakeBuddy();

  };

  class Buddy: public Piece {
  public:
    Buddy() {
      _stprintf(classname, L"Buddy");
    }
  };

  void Item::MakeBuddy() {
    pieces[pieceCount++] = new Buddy();
  }

  int _tmain(int argc, _TCHAR* argv[]) {
    for (int i=0; i<MAX_PIECES; ++i) {
      pieces[i] = 0;
    }

    pieces[pieceCount++] = new Item();

    Piece *piece = new Item();
    pieces[pieceCount++] = piece;

    for (int i=0; i<pieceCount; ++i) {
      if (pieces[i])
        delete pieces[i];
    }
    return 0;
  }

C# source

  namespace IncrementIssueSharp {
    class Program {
      const int MAX_PIECES = 5;

      class Piece {
        protected string classname;
      }

      static int pieceCount = 0;

      static Piece[] pieces = new Piece[MAX_PIECES];

      class Item: Piece {
        public Item() {
          classname = "Item";
          MakeBuddy();
        }
        private void MakeBuddy() {
          pieces[pieceCount++] = new Buddy();
        }
      }

      class Buddy: Piece {
        public Buddy() {
          classname = "Buddy";
        }
      }

      static void Main(string[] args) {
        pieces[pieceCount++] = new Item();

        Piece piece = new Item();
        pieces[pieceCount++] = piece;
      }
    }
  }
Posted in Uncategorized | Leave a comment

My Xbox recommends…


I think the “picks” section of the Xbox dashboard is a nice feature. From time to time I might post what it’s recommending, if it changes often enough. This time, I have:

All indie games! I bought Soulcaster, since it’s by the same person who made Escape Goat. We’ll see if that changes anything, in maybe a week or so.

 

Posted in Uncategorized | Tagged , , , | Leave a comment

My stupid controversial programming practices


1. The first non-whitespace character on any line must not be an opening brace.

1a. It’s called a brace, not a “curly bracket.”

2. Tab-aligning anything except initial indentation is a waste of time.

3. Trial and error is a fine way to program if you can do it fairly quickly.

4. If you can’t type 75+ wpm, that’s the next thing you should learn.

5. The mouse is for emergency use only.

6. There can be only one monitor.

7. If you’re listening to music while programming, you’re not reaching your full potential.

8. You should “reinvent the wheel” many, many times during your programming career.

9. The Visual C++ 6 IDE is the best IDE that ever was, or ever will be.

10. vi is awesome.

Posted in Uncategorized | Tagged , | Leave a comment

Serialization with delegates, and the Xbox


When it came to implementing serialization, for saving game status, I began with XmlSerializer, since it was in the XNA samples. Then I had a problem – it would not serialize delegate members.

A delegate is essentially a function pointer. The Quake2-based project originally used these, and I wanted to retain them. Its save file just wrote the functions as offsets; since it was a dynamically loaded DLL with a known exported function, pointer arithmetic could subtract any function’s address from the known one, and add it back on load. Of course if the DLL was recompiled, this might invalidate existing saves.

Since C# doesn’t allow for such function pointer arithmetic, another way was needed. Some searching didn’t really help too much, although the closest to what I eventually implemented was to have a map of identifiers to functions, and save the identifiers.

Before getting to where I am now, it’s worth noting that BinaryFormatter is able to serialize delegates, it is just not supported on the Xbox.

On to the implementation. Suppose you have this class, with delegate members, which you want to serialize:

class GamePiece {
  public delegate void _Update(GameTime gameTime);
  public _Update Update;

  void Walk(GameTime gameTime) {
  }

  void Somersault(GameTime gameTime) {
  }
}

Three things may occur on the Update member: it may be assigned to; its value may be checked; and it may be called. The first thing to do is to make it non-public, so none of these can occur (from outside the class). Then, add an enum defining the types of things that can be assigned to it, and a private member of that type.

class GamePiece {
  delegate void _Update(GameTime gameTime);

  private _Update _update;

  public enum Behavior {
    Nothing,
    Standard,
    Custom_Somersault,
  }

  private Behavior _behavior;
  ...
}

I use two special types: Nothing, which leaves the delegate null; and Standard, which I use to map to virtual functions which may be overridden in subclasses. Everything else gets its own specialized entry.

Finally, add a public property of Behavior type – this is where all assignment and comparison happens – and a public method to wrap around the private delegate member, so we can actually call it.

  public void doUpdate(GameTime gameTime) {
    if (_update == null)
      return;
    _update(gameTime);
  }

  public Behavior behavior {
    get { return _behavior; }
    set {
      _behavior = value;
      switch (_behavior) {
        case Behavior.Nothing:
          _update = null;
          break;
        case Behavior.Standard:
          _update = Walk;
          break;
        case Behavior.Custom_Somersault:
          _update = Somersault;
          break;
        default:
          throw new Exception("Unknown behavior.");
      }
    }

Now, a GamePiece object can be used as such:

protected override void Update(GameTime gameTime) {
  GamePiece piece = new GamePiece();
  piece.doUpdate(gameTime); // does nothing
  piece.behavior = GamePiece.Behavior.Standard;
  piece.doUpdate(gameTime); // calls Walk();
  piece.behavior = GamePiece.Behavior.Custom_Somersault;
  piece.doUpdate(gameTime); // calls Somersault();
  if (piece.behavior == GamePiece.Behavior.Standard) {
    piece.behavior = GamePiece.Behavior.Nothing;
  }
}

(More realistically, you’d have some container of GamePiece objects, and just foreach/doUpdate on each.)

The last part is to put in the serialization methods. It may be helpful to create and inherit an interface, so you can treat any classes you design this way as the same type. I pass in BinaryReader and BinaryWriter objects; although using XmlSerializer instead is certainly an option.

  public void Serialize(BinaryWriter bw) {
    bw.Write((int) behavior);
  }

  public void Deserialize(BinaryReader br) {
    behavior = (Behavior) br.ReadInt32();
  }

The GamePiece object can now be serialized and deserialized, and maintain its “behavior” state. Note that the delegates are not really serialized, the Behavior representing them is; and also that the property is serialized, not the private Behavior member, so that it is properly deserialized (setting the delegate back up).

Edit: here is a simple project that demonstrates this, which I was able to run successfully on Xbox. It’s a .zip file with a VS2010 solution.
https://skydrive.live.com/redir?resid=2974B26BAC4EC9FB!128&authkey=!ALpQD9jXpMCouzk. I have not used skydrive before, so please let me know if this doesn’t work.

Posted in Uncategorized | Tagged , , | Leave a comment

Rebranding


I’m going to start calling this a “Quake2 based project” rather than a “port.” A port implies keeping existing functionality, and I have already scrapped quite a bit. The first thing to go was all the Winsock stuff – although I soon realized I could have used System.Net, all along I’ve planned to target XBLIG, and would have had to use the Xbox Live stuff. I think.

Anyhow, the initial “port” was in fact done some time ago; not necessarily bug-free nor feature-complete, but working, for the most part. Now all the work is revolving around making it work, and work well, on Xbox; object-orienting it, fixing bugs, and adding new things in support of an eventual game.

Here’s a list of things that have been fixed, or remain to be fixed, for eventual discussion (if any are worth discussing):

Things fixed

* monsters jumpy (turn interpolation off)

* items can’t be picked up

* weapons firing angle

* no damage to player

* sticky sliding against geometry

* func_* entities not working

* elevator doesn’t move (base1) – may be button issue

* some/all buttons not working

* exploding barrels don’t hurt player; grenades don’t damage monsters

* T_Damage – should dir be ref? YES

* very sluggish

* water doesn’t render

* number keys don’t work for weapons

* item change keys don’t work

* weapon trails invisible

* chaingun doesn’t shoot? auto-switches next when stopped

* visibility determination (bool nochecks)

* “entity was removed while using killtargets” – e.g. glass at beginning of base1

* first end of base2 at pipe; pipe cover renders oddly – backfacing?

* inverted crates at beginning of jail1, on conveyor belt??

* particles all white triangles

* base3 parasite hiding place rendered like inverted/backfacing

* rotating door shuts when should stay open

* button doesn’t change texture on push

* monsters fly backwards when shot without slowing

* armor not protecting?

* use hand grenades, blows up immediately, breaks all weapons

* door closes – turns black? (base1 first door)

* dead monsters pop back to walking frame – still don’t move or interact though – when leaving pvs?

* lasers not rendering (base3) – but they do work…R_DrawBeam?

* when PVS changes, things don’t persist – base2 end, bridge/toggle – probably same as monster popups

* picking up power cube crashes – illegible server message (map ware1)

* missing a power cube by the third one to be plugged in…

* monsters resurrect on return to level

* load game string formatting

* sprite animation exception (BFG fire)

* \n in F1/help text

* on changelevel, in new level, player sinks into floor

* monsters don’t turn to face walk direction (first time only?)

* gun kick/angle inverted (a/z keys to look up/down)

* feature: sound

* transparent brushes not transparent

* lasers not rendering correctly – check triangle list

* gltextures: max index exceeded.

* fix lerp and turn back on

* fix prediction

* plats very jumpy when player riding – map train, base2

* string formatting (help)

* make R_PolyBlend blend – pure white now

* centerprint doesn’t show on screen

* parasite/tongue, medic/cable not extending

* weapon trails trail along last shot vector, for a few shots

* light styles animate too fast

* timed powerups are too quick

* explosion animations too quick

* flashing hud numbers too quick

* flowing textures animate too fast

* feature: lightmapping

* “force field” not transparent

* alpha blending of text

* on load of save, entities disappear or don’t work

* sound sample rate off for some

* in the jail* series, turning off the yellow lasers breaks doors

* dynamic lights are black, and squares, not blending properly

Things to fix

* sky rendering improperly

* weapons poke through geometry (depth buffer?)

* text fuzzy – sampling issue?

* part of weapons can render in front of hud

* sprite transparency/blending

* pick up silencer automatically silences everything

* infantry machine gun fire too short

* polyblend too short

* loading screen doesn’t show

* when returning to a level, doors (etc) don’t work anymore – sometimes.

* blaster bolts aren’t oriented along path – parallel to ground, at least

* when entering level, not pointing in the right direction

* die and load autosave: exception: theGameClient.pers can be null

* pyramid doesn’t open

Posted in Uncategorized | Tagged , , , | Leave a comment

Blog Resurrection


I’ve spent the better part of the past year attempting to port Quake II to C# using the XNA framework. I’ll start posting a series of entries about what I’ve learned in the near future.

It all started with a Google search on how to improve collision detection on my previous project, but captured my full interest. It may or may not supplant what’s been previously posted, but it will surely contribute to a finished product.

Apologies for the delay.

Posted in Uncategorized | Tagged , , , | Leave a comment

Video progress report


This is a short video of the basic idea described before.

Todo List

1. end of game condition
2. layouts in xml
3. more levels
4. save/load completion data
5. duplicate project, clean up code
6. make some props not hit detectable
7. more obvious display of active offices
8. play sounds
9. investigate multiplayer

Posted in Uncategorized | Tagged , , | Leave a comment

Now with more purpose!


In just the past few weeks, I’ve been thinking more specifically about a game concept. For better or worse, the idea is to play as an office mailroom person, running around the building to pick up and deliver interoffice mail. It will be a first-person runner, I suppose.

Most of the “technology” needed is done, apart from Xbox Live support, which just seems like a good thing to have for what I’m picturing.

The single player experience is that you run around, and the HUD will show when an office has mail to be picked up (currently blue). You run to that office number, and then the HUD switches to the item’s destination office number (currently green). When delivered, it disappears. Multiple pickups and destinations may be in the queue at one time. I’m tracking overall time spent and distance travelled, and when all items have been delivered, best times/shortest distances will be saved.

Pickups and destinations will be in preconfigured layouts, and one physical level may have several layouts available to play. A random mode will also be supported. Random mode won’t be comparable to the built-in layouts, so best times and shortest distances would be saved separately, and ideally, the random layout would be saved with it, to be replayable.

Multiplayer would really be the same, except that there’s competition getting to the pickup location first, and number of deliveries would be part of the scoring system.

Small details and unknowns aside, that’s about all there is to it. It seems like fun, the way I’m imagining it.

It has been really helpful to have a definite idea, and be able to start implementing gameplay instead of just “technology demo” type features. Hopefully I’ll be at a point where this can go into playtest soon, at least for single player.

 

Posted in Uncategorized | Leave a comment

Horrible coincidence


I spent hours trying to find a bug with polygon sorting by material. I count the maximum number of polygons each material can have, then allocate that much to polygon lists. Each frame only adds the visible ones.

The test level had only three materials. Material 1 had 128 maximum, 2 had 154, and 3 had 40. I kept getting an out of bounds exception on material 1. It was trying to iterate through 154 polygons. Clearly the ordering got mixed up, and somewhere I was putting material 2’s polygons into material 1’s list? That’s what I thought, and combed through looking for, for hours.

Finally realized that it wasn’t crashing until frame 2. At the time, material 1 had 77 visible polygons, out of 128 possible. 77 * 2 = 154. It just happened to be the same number as material 2’s maximum.

The bug was in the way I clear the lists after each frame…materials without textures weren’t cleared.

 

Posted in Uncategorized | Leave a comment