#177007 - blessingta@hotmail.co.uk - Mon Nov 21, 2011 2:58 pm
hi
I'm trying to create a system that allows the player to input cheat codes
and so far Im trying the buffer system and I've been having errors (while loop wont terminate) with this visual studio trial I've done:
Plus whats the most memory safe/easiest way of implementing a player input buffer?
[/code]
I'm trying to create a system that allows the player to input cheat codes
and so far Im trying the buffer system and I've been having errors (while loop wont terminate) with this visual studio trial I've done:
Plus whats the most memory safe/easiest way of implementing a player input buffer?
Code: |
// linked list gba.cpp : Defines the entry point for the console application.
// #include "stdafx.h" #include <iostream> enum EKEYSTATE { a, b, c, d, e }; //BUFFER FOR CURRENT KEYS //Purpose: to store information about the keys in the current buffer struct SKey_buffer { volatile unsigned char vuc_KEYSTATE; SKey_buffer * next; bool bHead; }; SKey_buffer _buff6; SKey_buffer _buff5; SKey_buffer _buff4; SKey_buffer _buff3; SKey_buffer _buff2; SKey_buffer _buff1; SKey_buffer* iter;//iter head SKey_buffer * iter_Head;//temp storage for iter head SKey_buffer* iter_newNULL; //initialised to current null void BUFFER_keysinit(); void BUFFER_newKeys(volatile unsigned char a); int _tmain(int argc, _TCHAR* argv[]) { BUFFER_keysinit(); //this unsigned char will be replaced with enums after i know that the linked list is working properly volatile unsigned char a = 'A'; int i = 0; while (i < 200) { BUFFER_newKeys(a); a++; std::cout<<iter->vuc_KEYSTATE<<std::endl; i++; } return 0; } //initialise key input buffer void BUFFER_keysinit() { _buff6.next = NULL; _buff6.bHead = false; _buff5.next = &_buff6; _buff5.bHead = false; _buff4.next = &_buff5; _buff4.bHead = false; _buff3.next = &_buff4; _buff3.bHead = false; _buff2.next = &_buff3; _buff2.bHead = false; _buff1.next = &_buff2; _buff1.bHead = true; iter_Head = &_buff1;//head at initialisation iter = iter_Head; //head at start of traversing iter_newNULL = &_buff6; //initialised to current null } void BUFFER_newKeys(volatile unsigned char a) { /////////////////////////////////////////////////////////////////////////////// //section continuously executed //Locate current NULL while (iter->next != NULL) { //This will be the last iterrator prior the last, //NULL with wont be executed iter_newNULL->next = iter; iter = iter->next; } //iter == null if (iter->next == NULL) { //current NULL, = current state iter->vuc_KEYSTATE = a; //current NULL iter = New head //point to old head: set old head to false iter_Head->bHead = false; iter->next = iter_Head; iter->bHead = true; //NEW iter_head = "current NULL" iter_Head = iter; //active new null to null iter_newNULL->next = NULL; } /////////////////////////////////////////////////////////////////////////////// } |