6 new categories and 72 new items added to the shop!Fake forum EC for posting doubled everywhere to help pay for them!
0 Members and 1 Guest are viewing this topic.
/* * heap.h * SMAC/X Project * Brendan Casey * * v1.0 (6/30/14) * * Class to handle the low level heap operations to manage or allocate memory * Removed an unused error flag (+0) and an unused parameter from squeeze() */
Well, I don't really have a change log myself. I have made some comments at the top of my header files where I've been keeping comments.One thing we'll need to worry about at some point is having a unified code format. For example:Quote/* * heap.h * SMAC/X Project * Brendan Casey * * v1.0 (6/30/14) * * Class to handle the low level heap operations to manage or allocate memory * Removed an unused error flag (+0) and an unused parameter from squeeze() */
/* * heap.h * SMAC/X Project * Brendan Casey * * v1.0 (6/30/14) * * Class to handle the low level heap operations to manage or allocate memory * Removed an unused error flag (+0) and an unused parameter from squeeze() */#pragma once#include "stdafx.h"#include "general.h" // mem_get()class Heap{ private: LPVOID basePtr; // (+4) -> pointer to base memory address LPVOID currentPtr; // (+8) -> current memory address position size_t baseSize; // (+12) -> size of total memory size_t freeSize; // (+16) -> size of free available memory public: // Constructor and Destructor Heap(): basePtr(0), currentPtr(0), baseSize(0), freeSize(0) { } ~Heap() { shutdown(); } // Get base total memory size size_t getBaseSize() { return baseSize; } // Get base memory address pointer LPVOID getBasePtr() { return basePtr; } // Destroy current heap and zero out all class variables // LOCATION: 005D4580 void shutdown(); // Deflate heap of any free memory // LOCATION: 005D45E0 void squeeze(); // Allocate memory based on requested size from parameter // Return TRUE if memory allocation failed, otherwise FALSE // LOCATION: 005D4620 BOOL init(size_t reqSize); // Check if there is currently enough free memory for requested size from parameter // If not, allocate more memory to heap in blocks of 1024 bytes until there is enough // Return a memory pointer with address to requested size free // LOCATION: 005D4680 LPVOID get(size_t reqSize);};
/* * heap.cpp * SMAC/X Project * Brendan Casey * * v1.0 (6/30/14) * * Class to handle the low level heap operations to manage or allocate memory */#include "heap.h"void Heap::shutdown(){ if(basePtr){ free(basePtr); } basePtr = currentPtr = 0; baseSize = freeSize = 0;}void Heap::squeeze(){ size_t usedSize = baseSize - freeSize; LPVOID newAddr = realloc(basePtr, usedSize); if(newAddr){ basePtr = newAddr; baseSize = usedSize; freeSize = 0; }}BOOL Heap::init(size_t reqSize){ if(basePtr){ shutdown(); } basePtr = mem_get(reqSize); if(basePtr){ currentPtr = basePtr; baseSize = freeSize = reqSize; return FALSE; } return TRUE; // failed to allocate memory}LPVOID Heap::get(size_t reqSize){ while(freeSize < reqSize){ LPVOID newAddr = realloc(basePtr, baseSize + 1024); if(!newAddr){ CHAR szError[150]; // max size of string + three int(s) + extra wsprintf(szError, "Aborting due to a heap shortage!\nBase size: %d\nFree size: %d\nRequested size: %d", baseSize, freeSize, reqSize); MessageBox(NULL, szError, "Heap Notice!!", MB_OK); exit(3); } basePtr = newAddr; currentPtr = LPVOID(size_t(basePtr) + baseSize - freeSize); // fix in case realloc shifts memory baseSize += 1024; freeSize += 1024; } LPVOID freeMemAddr = currentPtr; freeSize -= reqSize; currentPtr = LPVOID(size_t(currentPtr) + reqSize); return freeMemAddr;}
Inside base structure:"Turns left to revolt: +7"This is actually the number of turns left until assimilation of the base is complete. Once it goes down to zero, the former faction is set to current faction and the base no longer looks like the previous owners bases.The info about base flags is useful, I only had rioting and golden age.
There are now 29 issues in the tracker. I'd like some feedback on tagging from anyone who's interested at some point. There are also a bunch of possible bugs that need discussion.Yitzi, would you be okay with me tracking feature requests from your thread on this?
Factions: Size 20CC. Faction 0 would have: Nessus at 96D1EC AI value for SUPPORT x at 96D080+4*x.virtual mineral count: 946138+4Xfac#