Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_Matrix.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2class SCR_Matrix
3{
4
5 private int m_iMaxColumns;
6 private int m_iMaxRows;
7
8// private ref SCR_Array m_Array;
9 private ref array<ref SCR_MatrixRow> m_iMatrix;
10
11 //------------------------------------------------------------------------------------------------
12 // ! reserve first free place of the size [sizeCols, sizeRows] in the matrix
13 array<int> Reserve1stFreePlace( int sizeCols, int sizeRows )
14 {
15 array<int> retVal;
16 for( int iRow = 0; iRow < m_iMatrix.Count(); iRow++ )
17 {
18 for( int iCol = 0; iCol < m_iMaxColumns; iCol++ )
19 {
20 retVal = ReservePlace( sizeCols, sizeRows, iCol, iRow );
21 if( ( retVal[0] != -1 ) && ( retVal[1] != -1 ) )
22 return retVal;
23 }
24 }
25
26 return retVal;
27 }
28
29 //------------------------------------------------------------------------------------------------
30 // ! reserve the place of the size [sizeCols, sizeRows] in the matrix starting on position [col, row]
31 array<int> ReservePlace( int sizeCols, int sizeRows, int col, int row )
32 {
33
34 if( ( sizeRows + row ) > m_iMatrix.Count() )
35 return {-1,-1}; //the item doesn't fit vertically
36
37 SCR_MatrixRow aRow = new SCR_MatrixRow( sizeCols );
38
39 //go through all rows
40 for( int iRow = row; iRow < ( sizeRows + row ); iRow++ )
41 {
42 GetRow( iRow, aRow ); //take the actual row
43 bool bFree = aRow.CheckFreePlaceInRow( sizeCols, col ); //check for the free place
44 if( !bFree )
45 return {-1,-1};
46 }
47 //TODO: checking and reserving can be done in one round!
48 //if there's enough free place, reserve it
49 for( int iRow = row; iRow < ( sizeRows + row ); iRow++ )
50 {
51 GetRow( iRow, aRow ); //take the actual row
52 aRow.ReservePlaceInRow( sizeCols, col );
53 }
54 return {col, row};
55 }
56
57 //------------------------------------------------------------------------------------------------
58 void Debug()
59 {
60 for( int i = 0; i < m_iMatrix.Count(); i++)
61 m_iMatrix.Get( i ).Debug();
62 }
63
64 //------------------------------------------------------------------------------------------------
65 private void GetRow( int rowIndex, out notnull SCR_MatrixRow row )
66 {
67 row = m_iMatrix.Get( rowIndex );
68 }
69
70 //------------------------------------------------------------------------------------------------
71 int GetElement( int col, int row )
72 {
73 //ref SCR_MatrixRow tmp = new SCR_MatrixRow( m_iMaxColumns );
74
75 int retVal = m_iMatrix.Get( row ).GetElement( col );
76 return retVal;
77 }
78
79 //------------------------------------------------------------------------------------------------
80 void SetElement( int col, int row, int value )
81 {
82 m_iMatrix.Get( row ).SetElement( col, value );
83 }
84
85
86 //------------------------------------------------------------------------------------------------
87 void InsertRow( SCR_MatrixRow row )
88 {
89 m_iMatrix.Insert( row );
90 }
91
92 void Reset()
93 {
94 for( int iLoop = 0; iLoop < m_iMaxRows; iLoop++ )
95 for( int jLoop = 0; jLoop < m_iMaxColumns; jLoop++ )
96 SetElement( jLoop, iLoop, 0);
97 }
98
99
100 //------------------------------------------------------------------------------------------------
101 void SCR_Matrix( int cols, int rows )
102 {
103 m_iMaxColumns = cols;
104 m_iMaxRows = rows;
105
106 m_iMatrix = new array<ref SCR_MatrixRow>();
107
108 for( int iLoop = 0; iLoop < rows; iLoop++ )
109 m_iMatrix.Insert( SCR_MatrixRow( cols ) );
110 }
111
112 //------------------------------------------------------------------------------------------------
113 void ~SCR_Matrix()
114 {
115 }
116
117};
void Reset()
void Debug()
Definition Types.c:327