the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "IntBuffer.h"
4
5//Allocates a new int buffer.
6//The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined.
7//It will have a backing array, and its array offset will be zero.
8//
9//Parameters:
10//capacity - The new buffer's capacity, in ints
11IntBuffer::IntBuffer(unsigned int capacity) : Buffer( capacity )
12{
13 buffer = new int[capacity];
14 memset( buffer,0,sizeof(int)*capacity);
15}
16
17IntBuffer::IntBuffer( unsigned int capacity, int *backingArray ) : Buffer( capacity )
18{
19 hasBackingArray = true;
20 buffer = backingArray;
21}
22
23IntBuffer::~IntBuffer()
24{
25 if( !hasBackingArray )
26 delete[] buffer;
27}
28
29int *IntBuffer::getBuffer()
30{
31 return buffer;
32}
33
34//Flips this buffer. The limit is set to the current position and then the position is set to zero.
35//If the mark is defined then it is discarded.
36//
37//Returns:
38//This buffer
39IntBuffer *IntBuffer::flip()
40{
41 m_limit = m_position;
42 m_position = 0;
43 return this;
44}
45
46//Absolute get method. Reads the int at the given index.
47//Parameters:
48//index - The index from which the int will be read
49//Returns:
50//The int at the given index
51int IntBuffer::get(unsigned int index)
52{
53 assert( index < m_limit );
54
55 return buffer[index];
56}
57
58//Relative bulk put method (optional operation).
59//This method transfers ints into this buffer from the given source array.
60//If there are more ints to be copied from the array than remain in this buffer, that is, if length > remaining(),
61//then no ints are transferred and a BufferOverflowException is thrown.
62//
63//Otherwise, this method copies length ints from the given array into this buffer, starting at the given offset in the array
64//and at the current position of this buffer. The position of this buffer is then incremented by length.
65//
66//In other words, an invocation of this method of the form dst.put(src, off, len) has exactly the same effect as the loop
67//
68// for (int i = off; i < off + len; i++)
69// dst.put(a[i]);
70//except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.
71//Parameters:
72//src - The array from which ints are to be read
73//offset - The offset within the array of the first int to be read; must be non-negative and no larger than array.length
74//length - The number of ints to be read from the given array; must be non-negative and no larger than array.length - offset
75//Returns:
76//This buffer
77IntBuffer *IntBuffer::put(intArray *inputArray, unsigned int offset, unsigned int length)
78{
79 assert( offset + length < inputArray->length );
80
81 std::copy( inputArray->data +offset, inputArray->data +offset+length, buffer+m_position );
82
83 m_position += length;
84
85 return this;
86}
87
88IntBuffer *IntBuffer::put(intArray inputArray)
89{
90 if( inputArray.length > remaining() )
91 assert( false ); //TODO 4J Stu - Some kind of exception?
92
93 std::copy( inputArray.data, inputArray.data + inputArray.length, buffer+m_position );
94
95 m_position += inputArray.length;
96
97 return this;
98}
99
100//Writes the given int into this buffer at the current position, and then increments the position.
101//
102//Parameters:
103//i - The int to be written
104//Returns:
105//This buffer
106IntBuffer *IntBuffer::put(int i)
107{
108 assert( m_position < m_limit );
109
110 buffer[m_position++] = i;
111
112 return this;
113}