Results 1 to 1 of 1
  1. #1
    chooapple2200
    chooapple2200 is offline
    Guest
    Join Date
    2013 May
    Posts
    1
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0

    Tips on game programming at asm level

    Here is some programming tips for low-level game programming.

    C++ is probably one of the most common language for game programming. When programming the bot engine, such as a finite state machine fsm), generally the rules are implemented in the following format: state + event -> new_state

    /*
    suppose state and event are both variables.
    Also, lets say there are five values for state (using enum STATE1, STATE2, STATE3, STATE4, STATE5) and
    three event types (again using enum EVENT1, EVENT2, EVENT3).
    The following is a commonly found syntax of a fsm implementation:
    */

    if (state == STATE1 && EVENT == EVENT1) {
    ... ACTION 1 ....
    }
    else if (state == STATE1 && EVENT == EVENT2) {
    ... ACTION 2 ...
    }
    .... and so on.

    If the fsm is to be implemented at machine level through some assembly language, then the way to encode state and event would be quite different.
    Instead of encoding the five states as STATE1, STATE2 etc, which would eventually be converted to 0, 1, 2 etc,
    it is more efficient to encode the states using 5 bits which are all packed together in 1 byte:
    STATE1 becomes 00001
    STATE2 becomes 00010
    STATE3 becomes 00100
    and so on.
    The events can be implemented likewise using 3 bits: 001, 010, 100.

    There are many advantages for this implementation over using the integer values like 0, 1, 2, 3 etc.
    Here are the lovely properties of the 5-bit code format:
    First, the bit codes are all linearly independent unlike the integer-based codes. So, the state-event combination can be packed into a longer string of 8 bits. For example,
    STATE1 + EVENT1 -> STATE2
    00001 001 -> 00010 000
    This implementation greatly improves the processing speed.
    Second, this way of encoding events is closer to what really happens at the hardware level. If a bot is to be on a real mechanical device, it is likely that events are triggered by signals from sensors. For example, a bump on an obstacle triggers a tactile event, which turns on a tactile bit.

Similar Threads

  1. [Request] Starting in programming
    By AlCapone in forum Programming Tutorials
    Replies: 19
    Last Post: 2013-06-01, 09:14 PM
  2. [C++] Projects - beginner programming
    By marcogaruthi in forum Aika Online
    Replies: 5
    Last Post: 2013-05-06, 02:59 PM
  3. Replies: 0
    Last Post: 2013-05-02, 02:57 AM
  4. [Help] Tool for programming
    By nemsei in forum Aika Online
    Replies: 3
    Last Post: 2012-10-30, 03:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •