From 5ec08231a34505a895dd98935fa329e5af4985a0 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Tue, 10 Oct 2023 23:37:11 +0300 Subject: [PATCH 01/46] Match new with delete (#238) Only applicable if we actually fail to create a vsurface --- Standard Gaming Platform/vsurface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Standard Gaming Platform/vsurface.cpp b/Standard Gaming Platform/vsurface.cpp index 0df8bab7..905cf893 100644 --- a/Standard Gaming Platform/vsurface.cpp +++ b/Standard Gaming Platform/vsurface.cpp @@ -1190,7 +1190,7 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc ) DbgMessage( TOPIC_VIDEOSURFACE, DBG_LEVEL_2, String( "Failed to create Video Surface in video memory" ) ); DDReleaseSurface ( &lpDDS, &lpDDS2 ); - MemFree( hVSurface ); + delete hVSurface; return( NULL ); } From e6f1f40aea94707a08bfc7d5f724d6e9681b0bb2 Mon Sep 17 00:00:00 2001 From: zwwooooo Date: Sun, 15 Oct 2023 22:05:59 +0800 Subject: [PATCH 02/46] Fixed "14POINTARIAL" font height for Chinese Version. --- Standard Gaming Platform/WinFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Standard Gaming Platform/WinFont.cpp b/Standard Gaming Platform/WinFont.cpp index 223e634f..bd046f7c 100644 --- a/Standard Gaming Platform/WinFont.cpp +++ b/Standard Gaming Platform/WinFont.cpp @@ -505,7 +505,7 @@ INT16 GetWinFontHeight(INT32 iFont) if (pWinFont == NULL) return(0); #ifdef CHINESE //zwwooooo: Correct tactical interface font height to fixed Chinese characters smearing bug - if (iFont == WinFontMap[TINYFONT1] || iFont == WinFontMap[SMALLFONT1] || iFont == WinFontMap[WIN_14POINTARIAL]) + if (iFont == WinFontMap[TINYFONT1] || iFont == WinFontMap[SMALLFONT1] || iFont == WinFontMap[FONT14ARIAL]) { return pWinFont->Height + 2; } From a47ed9ed55d1286f338d8db6d6914cde815b2990 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Thu, 19 Oct 2023 19:08:39 +0300 Subject: [PATCH 03/46] Correct for loop end condition (#241) --- Tactical/World Items.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tactical/World Items.cpp b/Tactical/World Items.cpp index dd544fb4..341c79bd 100644 --- a/Tactical/World Items.cpp +++ b/Tactical/World Items.cpp @@ -136,7 +136,7 @@ void PruneWorldItems(void) for (size_t i = 0; i < gAllWorldItems.Items.size(); i++) { std::vector& items = gAllWorldItems.Items[i]; - for (INT32 j = items.size()-1; j > 0; j--) + for (INT32 j = items.size()-1; j >= 0; j--) { if (items[j].fExists == false) { From 8f454e2aab8b45e7dc845c15e39a530df5d5f0b1 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Fri, 20 Oct 2023 21:30:39 +0300 Subject: [PATCH 04/46] Container.cpp & .h delete (#242) * Remove GetFilesInDirectory() * Remove BuildFileDirectory * Remove container.cpp & .h Not used in the code --- Ja25Update.cpp | 1 - Standard Gaming Platform/CMakeLists.txt | 1 - Standard Gaming Platform/Container.cpp | 2104 ----------------------- Standard Gaming Platform/Container.h | 132 -- Standard Gaming Platform/FileMan.cpp | 166 -- Standard Gaming Platform/FileMan.h | 4 - Standard Gaming Platform/sgp.cpp | 4 - Standard Gaming Platform/vobject.h | 1 - Standard Gaming Platform/vsurface.h | 1 - Tactical/Faces.cpp | 1 - Tactical/PATHAI.cpp | 1 - Tactical/Soldier Control.cpp | 1 - Tactical/Soldier Tile.cpp | 1 - Tactical/bullets.cpp | 1 - Utils/Event Pump.cpp | 1 - Utils/Utils All.h | 3 +- aniviewscreen.cpp | 1 - 17 files changed, 1 insertion(+), 2423 deletions(-) delete mode 100644 Standard Gaming Platform/Container.cpp delete mode 100644 Standard Gaming Platform/Container.h diff --git a/Ja25Update.cpp b/Ja25Update.cpp index 101b1152..4fd737e1 100644 --- a/Ja25Update.cpp +++ b/Ja25Update.cpp @@ -11,7 +11,6 @@ #include "Animation Cache.h" #include "Animation Data.h" #include "Animation Control.h" -#include "container.h" #include #include "pathai.h" #include "Random.h" diff --git a/Standard Gaming Platform/CMakeLists.txt b/Standard Gaming Platform/CMakeLists.txt index e804d037..70404804 100644 --- a/Standard Gaming Platform/CMakeLists.txt +++ b/Standard Gaming Platform/CMakeLists.txt @@ -2,7 +2,6 @@ set(SGPSrc "${CMAKE_CURRENT_SOURCE_DIR}/Button Sound Control.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Button System.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Compression.cpp" -"${CMAKE_CURRENT_SOURCE_DIR}/Container.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Cursor Control.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/DEBUG.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/debug_util.cpp" diff --git a/Standard Gaming Platform/Container.cpp b/Standard Gaming Platform/Container.cpp deleted file mode 100644 index ad140dd5..00000000 --- a/Standard Gaming Platform/Container.cpp +++ /dev/null @@ -1,2104 +0,0 @@ -//***************************************************************************** -// -// Filename : Container.c -// -// Purpose : Function definition for the Container -// -// Modification History : -// 25 nov 96 TS creation -// -// 19 Dec 97 AM Replace all memcpy() with memmove(), since overlap possibilities -// abound (and there were already bugs in do_copy() for ordered lists) -// While the memcpy() was working in _DEBUG mode, it was failing -// reproducibly in RELEASE mode whenever regions overlapped! -// Having read the code, I strongly suggest that you DO NOT use this -// stuff at all and write your own instead. Tarun was no Carmack... -// - Alex Meduna -// 1998 KM Detached all references to this file from JA2 as it caused a lot of hard to debug -// crashes. The VOBJECT/VSURFACE lists are now self-maintained and no longer use the -// this crap. DON'T USE THIS -- NO MATTER WHAT!!! -//***************************************************************************** - - #include "types.h" - #include - #include - #include - #include "windows.h" - #include "MemMan.h" - #include "Debug.h" - #include "Container.h" - #if _MSC_VER < 1300 //(iostream.h was removed from VC.NET2003) - #include - #endif - - -//***************************************************************************** -// -// Defines and typedefs -// -// -//***************************************************************************** - -typedef struct StackHeaderTag -{ - UINT32 uiTotal_items; - UINT32 uiSiz_of_elem; - UINT32 uiMax_size; - -} StackHeader; - -typedef struct HeaderTag -{ - UINT32 uiTotal_items; - UINT32 uiSiz_of_elem; - UINT32 uiMax_size; - UINT32 uiHead; - UINT32 uiTail; - -} QueueHeader , ListHeader; - -typedef struct OrdHeaderTag -{ - UINT32 uiTotal_items; - UINT32 uiSiz_of_elem; - UINT32 uiMax_size; - UINT32 uiHead; - UINT32 uiTail; - INT8 (*pCompare)(void *,void *, UINT32); - -} OrdListHeader; - - typedef struct test - { - UINT32 me; - long you; - STR8 k; - STR8 p; - - } TEST; - -//***************************************************************************** -// -// CreateStack -// -// Parameter List : num_items - estimated number -// of items in stack -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** - -HSTACK CreateStack(UINT32 uiNum_items, UINT32 uiSiz_each) -{ - UINT32 uiAmount; - HSTACK hStack; - StackHeader *pStack; - - // assign an initial amount of memory to allocate - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Requested stack items and size have to be >0"); - return NULL; - } - // allocate the container memory - if ((hStack = MemAlloc(uiAmount + sizeof(StackHeader))) == 0) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Could not allocate stack container memory"); - return NULL; - } - pStack = (StackHeader *)hStack; - //initialize the header variables - pStack->uiMax_size = uiAmount + sizeof(StackHeader); - pStack->uiTotal_items = 0; - pStack->uiSiz_of_elem = uiSiz_each; - - // return the pointer to the memory - - return hStack; -} - -//***************************************************************************** -// -// CreateQueue -// -// Parameter List : num_items - estimated number -// of items in queue -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HQUEUE CreateQueue(UINT32 uiNum_items, UINT32 uiSiz_each) -{ - UINT32 uiAmount; - HQUEUE hQueue; - QueueHeader *pQueue; - - // check to see if the queue has more than 1 - // element to be created and that the size > 1 - - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Requested queue items and size have to be >0"); - return NULL; - } - - // allocate the queue memory - if ((hQueue = MemAlloc(uiAmount + sizeof(QueueHeader))) == 0) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Could not allocate queue container memory"); - return NULL; - } - - pQueue = (QueueHeader *)hQueue; - //initialize the queue structure - - pQueue->uiMax_size = uiAmount + sizeof(QueueHeader); - pQueue->uiTotal_items = 0; - pQueue->uiSiz_of_elem = uiSiz_each; - pQueue->uiTail = pQueue->uiHead = sizeof(QueueHeader); - - // return the pointer to memory - return hQueue; -} -//***************************************************************************** -// -// CreateList -// -// Parameter List : num_items - estimated number -// of items in ordered list -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HLIST CreateList(UINT32 uiNum_items, UINT32 uiSiz_each) -{ - UINT32 uiAmount; - HLIST hList; - ListHeader *pList; - - // check to see if the queue has more than 1 - // element to be created and that the size > 1 - - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Requested queue items and size have to be >0"); - return 0; - } - - // allocate the list memory - if ((hList = MemAlloc(uiAmount + sizeof(ListHeader))) == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not allocate queue container memory"); - return 0; - } - - pList = (ListHeader *)hList; - //initialize the list structure - - pList->uiMax_size = uiAmount + sizeof(ListHeader); - pList->uiTotal_items = 0; - pList->uiSiz_of_elem = uiSiz_each; - pList->uiTail = pList->uiHead = sizeof(ListHeader); - - // return the pointer to memory - - return hList; - -} - - - -//***************************************************************************** -// -// CreateOrdList -// -// Parameter List : num_items - estimated number -// of items in ordered list -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HORDLIST CreateOrdList(UINT32 uiNum_items, UINT32 uiSiz_each, INT8 (*compare)(void *, void *, UINT32)) -{ - UINT32 uiAmount; - HLIST hOrdList; - OrdListHeader *pOrdList; - - // check to see if the ordered list has more than 1 - // element to be created and that the size > 1 - - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Requested ordered list items and size have to be >0"); - return 0; - } - - // allocate the list memory - if ((hOrdList = MemAlloc(uiAmount + sizeof(OrdListHeader))) == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not allocate queue container memory"); - return 0; - } - - pOrdList = (OrdListHeader *)hOrdList; - //initialize the list structure - - pOrdList->uiMax_size = uiAmount + sizeof(OrdListHeader); - pOrdList->uiTotal_items = 0; - pOrdList->uiSiz_of_elem = uiSiz_each; - pOrdList->uiTail = pOrdList->uiHead = sizeof(OrdListHeader); - pOrdList->pCompare = compare; - - // return the pointer to memory - - return hOrdList; -} - - - -//***************************************************************************** -// -// push -// -// Parameter List : void * - pointer to stack -// container -// data - data to add to stack -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HSTACK Push(HSTACK hStack, void *pdata) -{ - StackHeader *pTemp_cont; - UINT32 uiOffset; - UINT32 uiNew_size; - void *pvoid; - BYTE *pbyte; - - // check for a NULL pointer - - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return NULL; - } - - // some valid data should be passed in - if (pdata == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto stack is NULL"); - return NULL; - } - - //perform operations to calculate offset and decide if the container has to resized - pTemp_cont = (StackHeader *)hStack; - uiOffset = (pTemp_cont->uiSiz_of_elem * pTemp_cont->uiTotal_items) + sizeof(StackHeader); - - if ((uiOffset + pTemp_cont->uiSiz_of_elem) > pTemp_cont->uiMax_size) - { - uiNew_size = pTemp_cont->uiMax_size + (pTemp_cont->uiMax_size - sizeof(StackHeader)); - pTemp_cont->uiMax_size = uiNew_size; - if ((hStack = MemRealloc(hStack, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Could not resize stack container memory"); - return NULL; - } - pTemp_cont = (StackHeader *)hStack; - } - pbyte = (BYTE *)hStack; - pbyte += uiOffset; - pvoid = (void *)pbyte; - //copy data from pdata to pvoid - the stack - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items++; - //return push succeeded - return hStack; -} -//***************************************************************************** -// -// pop -// -// Parameter List : void * - pointer to stack -// container -// -// -// Return Value : void * - pointer to stack -// after pushing element -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN Pop(HSTACK hStack, void *pdata) -{ - StackHeader *pTemp_cont; - UINT32 uiOffset; - UINT32 uiSize_of_each; - UINT32 uiTotal; - void *pvoid; - BYTE *pbyte; - - // check for a NULL queue - - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Variable where data is to be stored is NULL"); - return FALSE; - } - pTemp_cont = (StackHeader *)hStack; - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - if (uiTotal == 0) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "There is no data in stack to pop"); - return FALSE; - } - - // calculate offsets to decide if the page should be rezied - uiOffset = (uiSize_of_each * uiTotal) + sizeof(StackHeader); - uiOffset -= uiSize_of_each; - pbyte = (BYTE *)hStack; - pbyte += uiOffset; - pvoid = (void *)pbyte; - // get the data from pvoid and store in pdata - memmove(pdata, pvoid, uiSize_of_each); - pTemp_cont->uiTotal_items--; - return TRUE; -} -//***************************************************************************** -// -// PeekStack -// -// Parameter List : void * - buffer to hold data -// -// -// Return Value : TRUE if stack not empty -// -// Modification History : -// Apr 14 2000 SCT->Created -// -//***************************************************************************** -BOOLEAN PeekStack(HSTACK hStack, void *pdata) -{ - StackHeader *pTemp_cont; - UINT32 uiOffset; - UINT32 uiSize_of_each; - UINT32 uiTotal; - void *pvoid; - BYTE *pbyte; - - // check for a NULL queue - - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Variable where data is to be stored is NULL"); - return FALSE; - } - pTemp_cont = (StackHeader *)hStack; - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - if (uiTotal == 0) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "There is no data in stack to pop"); - return FALSE; - } - - // calculate offsets to decide if the page should be rezied - uiOffset = (uiSize_of_each * uiTotal) + sizeof(StackHeader); - uiOffset -= uiSize_of_each; - pbyte = (BYTE *)hStack; - pbyte += uiOffset; - pvoid = (void *)pbyte; - // get the data from pvoid and store in pdata - memmove(pdata, pvoid, uiSize_of_each); - return TRUE; -} -//***************************************************************************** -// -// DeleteStack -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteStack(HSTACK hStack) -{ - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return FALSE; - } - // free the memory assigned to the handle - MemFree(hStack); - return TRUE; -} -//***************************************************************************** -// -// DeleteQueue -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteQueue(HQUEUE hQueue) -{ - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return FALSE; - } - // free the memory assigned to the handle - MemFree(hQueue); - return TRUE; -} -//***************************************************************************** -// -// DeleteList -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteList(HLIST hList) -{ - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the list"); - return FALSE; - } - // free the memory assigned to the list - MemFree(hList); - return TRUE; -} -//***************************************************************************** -// -// DeleteOrdList -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteOrdList(HORDLIST hOrdList) -{ - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the ordered list"); - return FALSE; - } - // free the memory assigned to the list - MemFree(hOrdList); - return TRUE; -} -//***************************************************************************** -// -// InitializeContainers -// -// Parameter List : none -// -// Return Value : void -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** - -void InitializeContainers(void) -{ - // register the appropriate debug topics - RegisterDebugTopic(TOPIC_STACK_CONTAINERS, "Stack Container"); - RegisterDebugTopic(TOPIC_LIST_CONTAINERS, "List Container"); - RegisterDebugTopic(TOPIC_QUEUE_CONTAINERS, "Queue Container"); - RegisterDebugTopic(TOPIC_ORDLIST_CONTAINERS, "Ordered List Container"); -} - -//***************************************************************************** -// -// ShutdownContainers -// -// Parameter List : none -// -// Return Value : void -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** - -void ShutdownContainers( void ) -{ - UnRegisterDebugTopic(TOPIC_STACK_CONTAINERS, "Stack Container"); - UnRegisterDebugTopic(TOPIC_LIST_CONTAINERS, "List Container"); - UnRegisterDebugTopic(TOPIC_QUEUE_CONTAINERS, "Queue Container"); - UnRegisterDebugTopic(TOPIC_ORDLIST_CONTAINERS, "Ordered List Container"); -} -//***************************************************************************** -// -// PeekQueue - gets the first item in queue without -// actually deleting it. -// -// Parameter List : pvoid_queue - pointer to queue -// container -// data - data removed from queue -// -// Return Value pointer to queue with data removed -// or NULL if failed -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN PeekQueue(HQUEUE hQueue, void *pdata) -{ - QueueHeader *pTemp_cont; - void *pvoid; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from queue is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (QueueHeader *)hQueue; - - // if theres no elements to remove return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "There is nothing in the queue"); - return FALSE; - } - - //copy the element pointed to by uiHead - - pbyte = (BYTE *)hQueue; - pbyte += pTemp_cont->uiHead; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} -//***************************************************************************** -// -// PeekList - gets the specified item in the list without -// actually deleting it. -// -// Parameter List : hList - pointer to list -// container -// data - data where list element is stored -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN PeekList(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - void *pvoid; - UINT32 uiOffsetSrc; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the list"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (ListHeader *)hList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There is nothing in the list"); - return FALSE; - } - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There is no item at this position"); - return FALSE; - } - - //copy the element pointed to by uiHead - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hList; - pbyte += uiOffsetSrc; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} - - -//***************************************************************************** -// -// SwapListNode - Swaps the contents of a list node with the given parameter. -// Note: The data being swapped in MUST have the same size as -// the current node size or strange things could happen. -// Contents of node and pdata parameter are swapped. -// -// Parameter List : hList - pointer to list container -// pdata - pointer to data to be swapped -// uiPos - List position with which to swap. -// -// Return Value BOOLEAN - TRUE if successful, FALSE if function fails. -// -// -// Modification History : -// Added to SGP by Bret Rowdon for use with JA2. May 1 '97. -// - This function was based on the PeekList function. -// -//***************************************************************************** -BOOLEAN SwapListNode(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - BYTE *pvoid; - UINT32 uiOffsetSrc; - BYTE *pbyte; - BYTE *pSrc; - - - // cannot check for invalid handle, only 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer to list"); - return FALSE; - } - - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data pointer to be swapped from list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (ListHeader *)hList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Empty list"); - return FALSE; - } - - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid list position"); - return FALSE; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hList; - pbyte += uiOffsetSrc; - pvoid = pbyte; - pSrc = (BYTE *) pdata; - - // possible overlap, use memmove() - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - //memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} - - - -//***************************************************************************** -// -// StoreListNode - Stores the contents of a list node with the given parameter. -// Unlike SwapListNode(), this does NOT swap previous contents -// back into the pdata buffer! -// -// Parameter List : hList - pointer to list container -// pdata - pointer to data to be stored -// uiPos - List position into which to store. -// -// Return Value BOOLEAN - TRUE if successful, FALSE if function fails. -// -// -// Modification History : -// Added to SGP by Alex Meduna for use with Wiz8. Oct 31 '97. -// - This function is nearly identical to the SwapListNode() function. -// -//***************************************************************************** -BOOLEAN StoreListNode(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - UINT32 uiOffsetSrc; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer to list"); - return FALSE; - } - - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data pointer to be swapped from list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (ListHeader *)hList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Empty list"); - return FALSE; - } - - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid list position"); - return FALSE; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hList; - pbyte += uiOffsetSrc; - - memmove(pbyte, pdata, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} - - - -//***************************************************************************** -// -// PeekOrdList - gets the specified item in the list without -// actually deleting it. -// -// Parameter List : hList - pointer to ordered list -// container -// data - data where list element is stored -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN PeekOrdList(HORDLIST hOrdList, void *pdata, UINT32 uiPos) -{ - OrdListHeader *pTemp_cont; - void *pvoid; - UINT32 uiOffsetSrc; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the ordered list"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from ordered list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (OrdListHeader *)hOrdList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There is nothing in the list"); - return FALSE; - } - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There is no item at this position"); - return FALSE; - } - - //copy the element pointed to by uiHead - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hOrdList; - pbyte += uiOffsetSrc; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} -//***************************************************************************** -// -// RemfromQueue -// -// Parameter List : pvoid_queue - pointer to queue -// container -// data - data removed from queue -// -// Return Value pointer to queue with data removed -// or NULL if failed -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN RemfromQueue(HQUEUE hQueue, void *pdata) -{ - QueueHeader *pTemp_cont; - void *pvoid; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from queue is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (QueueHeader *)hQueue; - - // if theres no elements to remove return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "There is nothing in the queue to remove"); - return FALSE; - } - - //remove the element pointed to by uiHead - - pbyte = (BYTE *)hQueue; - pbyte += pTemp_cont->uiHead; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items--; - pTemp_cont->uiHead += pTemp_cont->uiSiz_of_elem; - - // if after removing an element head = tail then set them both - // to the beginning of the container as it is empty - - if (pTemp_cont->uiHead == pTemp_cont->uiTail) - pTemp_cont->uiHead = pTemp_cont->uiTail = sizeof(QueueHeader); - - // if only the head is at the end of the container then make it point - // to the beginning of the container - - if (pTemp_cont->uiHead == pTemp_cont->uiMax_size) - pTemp_cont->uiHead = sizeof(QueueHeader); - - return TRUE; -} - -//***************************************************************************** -// -// AddtoQueue -// -// Parameter List : pvoid_queue - pointer to queue -// container -// pdata - pointer to data to add to queue -// -// Return Value pointer to queue with data added -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HQUEUE AddtoQueue(HQUEUE hQueue, void *pdata) -{ - QueueHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiNew_size; - UINT32 uiHead; - UINT32 uiTail; - void *pvoid; - BYTE *pbyte; - BYTE *pmaxsize; - BYTE *presize; - BOOLEAN fresize; - - // check for invalid handle = 0 - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return NULL; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Data to be added onto queue is NULL"); - return NULL; - } - - // assign some temporary variables - fresize = FALSE; - pTemp_cont = (QueueHeader *)hQueue; - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - if ((uiTail + uiSize_of_each) > uiMax_size) - { - uiTail = pTemp_cont->uiTail = sizeof(QueueHeader); - fresize = TRUE; - } - if ((uiHead == uiTail) && ((uiHead >= (sizeof(QueueHeader) + uiSize_of_each)) || (fresize == TRUE))) - { - uiNew_size = uiMax_size + (uiMax_size - sizeof(QueueHeader)); - pTemp_cont->uiMax_size = uiNew_size; - if ((hQueue = MemRealloc(hQueue, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Could not resize queue container memory"); - return NULL; - } - // copy memory from beginning of container to end of container - // so that all the data is in one continuous block - - pTemp_cont = (QueueHeader *)hQueue; - presize = (BYTE *)hQueue; - pmaxsize = (BYTE *)hQueue; - presize += sizeof(QueueHeader); - pmaxsize += uiMax_size; - if (uiHead > sizeof(QueueHeader)) - memmove(pmaxsize, presize, uiHead-sizeof(QueueHeader)); - pTemp_cont->uiTail = uiMax_size + (uiHead-sizeof(QueueHeader)); - } - pbyte = (BYTE *)hQueue; - pbyte += pTemp_cont->uiTail; - pvoid = (void *)pbyte; - memmove(pvoid, pdata, uiSize_of_each); - pTemp_cont->uiTotal_items++; - pTemp_cont->uiTail += uiSize_of_each; - return hQueue; -} - -//***************************************************************************** -// -// do_copy -// -// Parameter List : pointer to mem, source offset, dest offset, size -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN do_copy(void *pmem_void, UINT32 uiSourceOfst, UINT32 uiDestOfst, UINT32 uiSize) -{ - BYTE *pOffsetSrc; - BYTE *pOffsetDst; - void *pvoid_src; - void *pvoid_dest; - - if ((uiSourceOfst < 0) || (uiDestOfst < 0) || (uiSize < 0)) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid parameters passed to do_copy"); - return FALSE; - } - - if (pmem_void == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer passed to do_copy"); - return FALSE; - } - pOffsetSrc = (BYTE *)pmem_void; - pOffsetSrc += uiSourceOfst; - pOffsetDst = (BYTE *)pmem_void; - pOffsetDst += uiDestOfst; - pvoid_src = (void *)pOffsetSrc; - pvoid_dest = (void *)pOffsetDst; - memmove(pvoid_dest, pvoid_src, uiSize); - return TRUE; -} -//***************************************************************************** -// -// do_copy_data -// -// Parameter List : pointer to mem, pointer to data, source offset, size -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN do_copy_data(void *pmem_void, void *data, UINT32 uiSrcOfst, UINT32 uiSize) -{ - BYTE *pOffsetSrc; - void *pvoid_src; - - if ((uiSrcOfst < 0) || (uiSize < 0)) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid parameters passed to do_copy_data"); - return FALSE; - } - - if (pmem_void == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer passed to do_copy_data"); - return FALSE; - } - pOffsetSrc = (BYTE *)pmem_void; - pOffsetSrc += uiSrcOfst; - pvoid_src = (void *)pOffsetSrc; - memmove(data, pvoid_src, uiSize); - return TRUE; -} -//***************************************************************************** -// -// StackSize -// -// Parameter List : pointer to stack -// -// Return Value UINT32 stack size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 StackSize(HSTACK hStack) -{ - StackHeader *pTemp_cont; - if (hStack == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Stack pointer is NULL"); - return 0; - } - pTemp_cont = (StackHeader *)hStack; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// QueueSize -// -// Parameter List : pointer to queue -// -// Return Value UINT32 queue size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 QueueSize(HQUEUE hQueue) -{ - QueueHeader *pTemp_cont; - if (hQueue == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Queue pointer is NULL"); - return 0; - } - pTemp_cont = (QueueHeader *)hQueue; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// ListSize -// -// Parameter List : pointer to queue -// -// Return Value UINT32 list size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 ListSize(HLIST hList) -{ - ListHeader *pTemp_cont; - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "List pointer is NULL"); - return 0; - } - pTemp_cont = (ListHeader *)hList; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// OrdListSize -// -// Parameter List : pointer to list -// -// Return Value UINT32 Ordlist size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 OrdListSize(HORDLIST hOrdList) -{ - OrdListHeader *pTemp_cont; - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Ordered List pointer is NULL"); - return 0; - } - pTemp_cont = (OrdListHeader *)hOrdList; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// AddtoList -// -// Parameter List : HCONTAINER - handle to list -// container -// data - data to add to queue -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HLIST AddtoList(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiNew_size; - UINT32 uiHead; - UINT32 uiTail; - void *pvoid; - BYTE *pbyte; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - BOOLEAN fTail_check=FALSE; - - // check for invalid handle = 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the list"); - return NULL; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return NULL; - } - // check for a 0 or negative position passed in - if (uiPos < 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return NULL; - } - - // assign some temporary variables - - pTemp_cont = (ListHeader *)hList; - if (uiPos > pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There are not enough elements in the list"); - return NULL; - } - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - uiMax_size); - if (uiTail == uiOffsetSrc) - fTail_check = TRUE; - // copy appropriate blocks - if (((uiTail + uiSize_of_each) <= uiMax_size) && - ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(ListHeader))))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (fTail_check == FALSE) - { - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - } - if (fTail_check == FALSE) - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail < uiHead)) - || (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead >= (sizeof(ListHeader) + uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - uiFinalLoc = uiOffsetSrc; - } else - { - uiOffsetSrc = sizeof(ListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(ListHeader); - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - } - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - }// end if - - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail == uiHead) && (uiHead >= (sizeof(ListHeader) + uiSize_of_each))) - || (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead == sizeof(ListHeader)))) - { - // need to resize the container - uiNew_size = uiMax_size + (uiMax_size - sizeof(ListHeader)); - pTemp_cont->uiMax_size = uiNew_size; - if ((hList = MemRealloc(hList, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not resize list container memory"); - return NULL; - } - pTemp_cont = (ListHeader *)hList; - if (do_copy(hList, sizeof(ListHeader), uiMax_size, uiHead - sizeof(ListHeader)) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy list container memory"); - return NULL; - } - pTemp_cont->uiTail = uiMax_size + (uiHead-sizeof(ListHeader)); - - // now make place for the actual element - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } - - - // finally insert data at position uiFinalLoc - - pbyte = (BYTE *)hList; - if (uiFinalLoc == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This should never happen! report this problem!"); - return NULL; - } - pbyte += uiFinalLoc; - pvoid = (void *)pbyte; - - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items++; - if (fTail_check == TRUE) - pTemp_cont->uiTail += pTemp_cont->uiSiz_of_elem; - return hList; -} - -//***************************************************************************** -// -// RemfromList -// -// Parameter List : HLIST - handle to list -// container -// data - data to remove from list -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN RemfromList(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiHead; - UINT32 uiTail; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - - // check for invalid handle = 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the list"); - return FALSE; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return FALSE; - } - // check for a 0 or negative position passed in - if (uiPos < 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return FALSE; - } - - // assign some temporary variables - pTemp_cont = (ListHeader *)hList; - - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Cannot delete at the specified position"); - return FALSE; - } - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There are no elements in the list to remove"); - return FALSE; - } - - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - - // copy appropriate blocks - if ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(ListHeader)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (do_copy_data(hList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not remove the data the list"); - return FALSE; - } - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } - - - if ((uiTail < uiHead) || ((uiTail == uiHead) && (uiHead <= (sizeof(ListHeader)+uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - uiFinalLoc = uiOffsetSrc; - } - else - { - uiOffsetSrc = sizeof(ListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(ListHeader); - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - } - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } // end if - - return TRUE; -} - - - -//***************************************************************************** -// -// RemfromOrdList -// -// Parameter List : HORDLIST - handle to ordered list -// container -// data - data to remove from ordered list -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN RemfromOrdList(HORDLIST hOrdList, void *pdata, UINT32 uiPos) -{ - OrdListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiHead; - UINT32 uiTail; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - - - // check for invalid handle = 0 - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the ordered list"); - return FALSE; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto ordered list is NULL"); - return FALSE; - } - // check for a 0 or negative position passed in - if (uiPos < 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto ordered list is NULL"); - return FALSE; - } - - // assign some temporary variables - - pTemp_cont = (OrdListHeader *)hOrdList; - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Cannot delete at the specified position"); - return FALSE; - } - - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There are no elements in the ordered list to remove"); - return FALSE; - } - - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - - // copy appropriate blocks - if ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(OrdListHeader)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (do_copy_data(hOrdList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from ordered list"); - return FALSE; - } - - if (do_copy(hOrdList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not remove the data from the ordered list"); - return FALSE; - } - - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } - - - if ((uiTail < uiHead) || ((uiTail == uiHead) && (uiHead <= (sizeof(OrdListHeader)+uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hOrdList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiFinalLoc = uiOffsetSrc; - } - else - { - uiOffsetSrc = sizeof(OrdListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(OrdListHeader); - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hOrdList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - } - - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } // end if - - - return TRUE; -} - - - -//***************************************************************************** -// -// StoreinOrdList -// -// Parameter List : HORDLIST - handle to ordered list -// container -// data - data to add to the ordered list -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HORDLIST StoreinOrdList(HORDLIST hOrdList, void *pdata, UINT32 uiPos) -{ - OrdListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiNew_size; - UINT32 uiHead; - UINT32 uiTail; - void *pvoid; - BYTE *pbyte; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - BOOLEAN fTail_check=FALSE; - - - // check for invalid handle = 0 - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the ordered list"); - return NULL; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto ordered list is NULL"); - return NULL; - } - - // assign some temporary variables - pTemp_cont = (OrdListHeader *)hOrdList; - - // check for invalid position - if (uiPos > pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There are not enough elements in the ordered list to add after"); - return NULL; - } - - - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - uiOffsetSrc = pTemp_cont->uiHead + (uiPos * pTemp_cont->uiSiz_of_elem); - - - // this shouldn't be necessary? position should never be outside the range? - if (uiOffsetSrc >= uiMax_size) - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - uiMax_size); - - if (uiTail == uiOffsetSrc) - fTail_check = TRUE; - - - // now copy the appropriate blocks to make room... - - if (((uiTail + uiSize_of_each) <= uiMax_size) && - ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(OrdListHeader))))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - - if (fTail_check == FALSE) - { - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in ordered list"); - return NULL; - } - } - - if (fTail_check == FALSE) - pTemp_cont->uiTail += uiSize_of_each; - - uiFinalLoc = uiOffsetSrc; - } - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail < uiHead)) || - (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead >= (sizeof(OrdListHeader) + uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - uiFinalLoc = uiOffsetSrc; - } - else - { - uiOffsetSrc = sizeof(OrdListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(OrdListHeader); - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - } - - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } // end if - - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail == uiHead) && (uiHead >= (sizeof(OrdListHeader) + uiSize_of_each))) - || (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead == sizeof(OrdListHeader)))) - { - // need to resize the container - uiNew_size = uiMax_size + (uiMax_size - sizeof(OrdListHeader)); - pTemp_cont->uiMax_size = uiNew_size; - - if ((hOrdList = MemRealloc(hOrdList, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not resize ordered list container memory"); - return NULL; - } - - pTemp_cont = (OrdListHeader *)hOrdList; - - if (do_copy(hOrdList, sizeof(OrdListHeader), uiMax_size, uiHead - sizeof(OrdListHeader)) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy ordered list container memory"); - return NULL; - } - - pTemp_cont->uiTail = uiMax_size + (uiHead-sizeof(OrdListHeader)); - - // now make place for the actual element - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } - - if (uiFinalLoc == 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This should never happen! report this problem!"); - return NULL; - } - - - // finally insert data at position uiFinalLoc - pbyte = (BYTE *)hOrdList; - pbyte += uiFinalLoc; - pvoid = (void *)pbyte; - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items++; - - if (fTail_check == TRUE) - pTemp_cont->uiTail += pTemp_cont->uiSiz_of_elem; - - return hOrdList; -} - - - -//***************************************************************************** -// -// AddtoOrdList -// -// Parameter List : HORDLIST - handle to ordered list -// container -// data - data to add to the ordered list -// -// Return Value BOOLEAN true if Add ok else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// Dec 19th 1997->verified, cleaned up, and heavily commented by AM -// -//***************************************************************************** -HORDLIST AddtoOrdList(HORDLIST hOrdList, void *pdata) -{ - OrdListHeader *pOrdList; - void *pTemp_data; - UINT32 uiOffset; - BOOLEAN fContinue = FALSE; - INT8 sbResult; - UINT32 uiPosition; - - - // get a pointer into the list header - pOrdList = (OrdListHeader *)hOrdList; - - - // if the list is empty or full) - if (pOrdList->uiHead == pOrdList->uiTail) - { - // if the head offset points to position 0, presumably that means it's empty (?) - if (pOrdList->uiHead == sizeof(OrdListHeader)) - { - // so store it in position 0 - if ((hOrdList = StoreinOrdList(hOrdList, pdata, 0)) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data into ordered list"); - return NULL; - } - - return hOrdList; - } - - // set flag to go through the while loop even though head == tail - fContinue = TRUE; - } - - - // grab enough space to store one list entry - pTemp_data = MemAlloc(pOrdList->uiSiz_of_elem); - - // start offset by pointing at the last entry in the the list - uiOffset = pOrdList->uiTail; - - // figure out the index of the entry that the tail points to - uiPosition = (pOrdList->uiTail - sizeof(OrdListHeader)) / pOrdList->uiSiz_of_elem; - - - // continue looping while offset hasn't reached the start of the list yet (or at least once if list is full) - while ((uiOffset != pOrdList->uiHead) || (fContinue)) - { - // when offset reaches the top of the list - if (uiOffset == sizeof(OrdListHeader)) - { - // wrap around to the very bottom of the list (guaranteed to hold data?) - uiOffset = pOrdList->uiMax_size; - uiPosition = (pOrdList->uiMax_size - sizeof(OrdListHeader)) / pOrdList->uiSiz_of_elem; - } - - // get entry data at the current offset position and store it in pTemp_data - if (do_copy_data(hOrdList, pTemp_data, (uiOffset - pOrdList->uiSiz_of_elem), pOrdList->uiSiz_of_elem ) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - MemFree(pTemp_data); - return NULL; - } - - // run the compare function - sbResult = pOrdList->pCompare(pTemp_data, pdata, pOrdList->uiSiz_of_elem); - - // and do the right thing based on the result... - switch (sbResult) - { - case ORDLIST_ERROR : - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not perform comparison for ordered lists"); - MemFree(pTemp_data); - return NULL; - } - - case ORDLIST_EQUAL : - case ORDLIST_LEFT_LESS : - { - // found the right spot! Insert it at the current position - if ((hOrdList = StoreinOrdList(hOrdList, pdata, uiPosition)) == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data into ordered list"); - MemFree(pTemp_data); - return NULL; - } - return hOrdList; - } - - case ORDLIST_RIGHT_LESS : - { - // keep looking - uiOffset -= pOrdList->uiSiz_of_elem; - uiPosition--; - break; - } - - default : - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Invalid result received from Compare function"); - MemFree(pTemp_data); - return NULL; - } - } // end switch - - fContinue = FALSE; - } // end while - - - // don't need this anymore - MemFree(pTemp_data); - pTemp_data = NULL; - - - // never found the right spot, which means we must have reached the head (damn well better) - if (uiOffset != pOrdList->uiHead) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "ERROR - left the while loop but not at the head"); - return NULL; - } - - // the new item will be first in list, so calculate the position based on the head - uiPosition = (pOrdList->uiHead - sizeof(OrdListHeader)) / pOrdList->uiSiz_of_elem; - - // and stick it in there... - if ((hOrdList = StoreinOrdList(hOrdList, pdata, uiPosition)) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data into ordered list"); - return NULL; - } - - - return hOrdList; -} - - - -INT8 Compare(void *p, void *q, UINT32 size) -{ - TEST *temp1; - TEST *temp2; - - - temp1 = (TEST *)p; - temp2 = (TEST *)q; - - if (temp1->me < temp2->me) - return ORDLIST_LEFT_LESS; - - if (temp1->me > temp2->me) - return ORDLIST_RIGHT_LESS; - - if (temp1->me == temp2->me) - return ORDLIST_EQUAL; - - return ORDLIST_ERROR; -} diff --git a/Standard Gaming Platform/Container.h b/Standard Gaming Platform/Container.h deleted file mode 100644 index 69dfe1f5..00000000 --- a/Standard Gaming Platform/Container.h +++ /dev/null @@ -1,132 +0,0 @@ -//*********************************************** -// -// Filename : Container.h -// -// Purpose : prototypes for the container file -// -// Modification History : 25 Nov 96 Creation -// -//*********************************************** - -#ifndef _CONTAINER_H -#define _CONTAINER_H - -//*********************************************** -// -// Includes -// -// -//*********************************************** - -#include "types.h" - -//*********************************************** -// -// Defines and typedefs -// -//*********************************************** -#define ORDLIST_ERROR -1 -#define ORDLIST_EQUAL 0 -#define ORDLIST_LEFT_LESS 1 -#define ORDLIST_RIGHT_LESS 2 - -typedef void * HCONTAINER; -typedef HCONTAINER HSTACK; -typedef HCONTAINER HQUEUE; -typedef HCONTAINER HLIST; -typedef HCONTAINER HORDLIST; - -//*********************************************** -// -// Function Prototypes -// -//*********************************************** -#ifdef __cplusplus -extern "C" { -#endif - -// call these functions to initialize and shutdown the debug messages for -// containers -extern void InitializeContainers(void); -extern void ShutdownContainers(void); - -// Stack Functions -// CreateStack(estimated number of items in stack, size of each item -// Push(handle to container returned from CreateStack, data to be passed in (must be void *) -// : returns handle to new stack -// Pop(handle to container returned from CreateStack, data to be passed in (must be void *) -// : returns BOOLEAN -// DeleteStack deletes the stack container -// StackSize returns size of stack - -extern HSTACK CreateStack(UINT32 num_of_elem , UINT32 siz_of_each); -extern HSTACK Push(HSTACK hStack, void *data); -extern BOOLEAN Pop(HSTACK hStack, void *data); -extern UINT32 StackSize(HSTACK hStack); -extern BOOLEAN DeleteStack(HSTACK hStack); -extern BOOLEAN PeekStack(HSTACK hStack, void *data); - -// Queue Functions -// CreateQueue(estimated number of items in queue, size of each item -// AddtoQueue(handle to container returned from CreateQueue, data to be passed in (must be void *)) -// : returns handle to queue -// RemfromQueue(handle to container returned from CreateQueue, variable where data is stored (must be void *)) -// : returns BOOLEAN -// PeekQueue(handle to the queue, variable where peeked data is stored). Item is not deleted. -// : returns BOOLEAN -// QueueSize(handle to the queue) returns the queue size -// DeleteQueue(handle to container) Delete the queue container -// : returns BOOLEAN - -extern HQUEUE CreateQueue(UINT32 num_of_elem, UINT32 siz_of_each); -extern HQUEUE AddtoQueue(HQUEUE hQueue, void *data); -extern BOOLEAN RemfromQueue(HQUEUE hQueue,void *data); -extern BOOLEAN PeekQueue(HQUEUE hQueue, void *data); -extern UINT32 QueueSize(HQUEUE hQueue); -extern BOOLEAN DeleteQueue(HQUEUE hQueue); - -// List Functions -// CreateList(estimated number of items in queue, size of each item -// AddtoList(handle to container returned from CreateQueue, data to be passed in (must be void *) -// position where data is to be added (0...sizeof(list)) -// : returns handle to new list -// RemfromList(handle to container returned from CreateList, variable where data is stored (must be void *) -// position where data is to be deleted (0...sizeof(list)-1) -// PeekList(handle to the list, variable where peeked data is stored). Item is not deleted. -// position where data is to be peeked (0...sizeof(list)-1) -// ListSize(handle to the list) returns the list size -// DeleteList(handle to the list) Delete the list container - -extern HLIST CreateList(UINT32 num_of_elem, UINT32 siz_of_each); -extern HLIST AddtoList(HLIST hList, void *data, UINT32 position); -extern BOOLEAN RemfromList(HLIST hList,void *data, UINT32 position); -extern BOOLEAN PeekList(HLIST hList, void *data, UINT32 position); -extern UINT32 ListSize(HLIST hList); -extern BOOLEAN DeleteList(HLIST hList); -extern BOOLEAN SwapListNode(HLIST hList, void *pdata, UINT32 uiPos); -extern BOOLEAN StoreListNode(HLIST hList, void *pdata, UINT32 uiPos); - -// Ordered List Functions -// CreateOrdList(estimated number of items in ordered list, size of each item, -// pointer to a compare function that returns info on whether the data in the ordered stack -// is < or > the new data to be added into the ordered list. -// AddtoOrdList(handle to container returned from CreateOrdList, data to be passed in (must be void *) -// RemfromOrdList(handle to container returned from CreateList, variable where data is stored (must be void *) -// position where data is to be deleted (0...sizeof(list)-1) -// PeekOrdList(handle to the list, variable where peeked data is stored). Item is not deleted. -// position where data is to be peeked (0...sizeof(list)-1) -// OrdListSize(handle to the list) returns the ordered list size -// DeleteOrdList(handle to the list) Delete the ordered list container - -extern HLIST CreateOrdList(UINT32 num_of_elem, UINT32 siz_of_each, INT8 (*compare)(void *,void *, UINT32)); -extern HLIST AddtoOrdList(HLIST hList, void *data); -extern BOOLEAN RemfromOrdList(HLIST hList,void *data, UINT32 position); -extern BOOLEAN PeekOrdList(HLIST hList, void *data, UINT32 position); -extern UINT32 OrdListSize(HLIST hList); -extern BOOLEAN DeleteOrdList(HLIST hList); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 9e4c3804..ec348b16 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -36,7 +36,6 @@ #include "MemMan.h" #include "Debug.h" #include "RegInst.h" - #include "Container.h" #include "LibraryDataBase.h" #include "io.h" #include "sgp_logger.h" @@ -149,8 +148,6 @@ void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ); HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ); HWFILE CreateFileHandle( HANDLE hRealFile, BOOLEAN fDatabaseFile ); void DestroyFileHandle( HWFILE hFile ); -void BuildFileDirectory( void ); -INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *, HANDLE hFile, WIN32_FIND_DATA *pFind ); //************************************************************************** // @@ -950,169 +947,6 @@ void DestroyFileHandle( HWFILE hFile ) */ - -//************************************************************************** -// -// BuildFileDirectory -// -// -// -// Parameter List : -// Return Value : -// Modification history : -// -// ??nov96:HJH ->creation -// -//************************************************************************** - -void BuildFileDirectory( void ) -{ - - return; // temporary until container stuff is fixed -/* - INT32 i, iNumFiles = 0; - HANDLE hFile, hFileIn; - WIN32_FIND_DATA find, inFind; - BOOLEAN fMore = TRUE; - CHAR cName[FILENAME_LENGTH], cDir[FILENAME_LENGTH], cSubDir[FILENAME_LENGTH]; - HCONTAINER hStack; - - - - // - // First, push all the file names in the directory (and subdirectories) - // onto the stack. - // - - GetProfileChar( "Startup", "InstPath", "", cDir ); - - if ( strlen( cDir ) == 0 ) - return; - - hStack = CreateStack( 100, FILENAME_LENGTH ); - if (hStack == NULL) - { - FastDebugMsg(String("BuildFileDirectory: CreateStack Failed for the filename stack")); - return; - } - - find.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - - strcpy( &(cDir[strlen(cDir)]), "\\*.*\0" ); - hFile = FindFirstFile( cDir, &find ); - while ( fMore ) - { - if ( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) - { - if ( strcmp( find.cFileName, "." ) != 0 && strcmp( find.cFileName, ".." ) != 0 ) - { - // a valid directory - inFind.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - strcpy( cSubDir, cDir ); - strcpy( &(cSubDir[strlen(cDir)-3]), find.cFileName ); - strcpy( &(cSubDir[strlen(cSubDir)]), "\\*.*\0" ); - hFileIn = FindFirstFile( cSubDir, &inFind ); - iNumFiles += GetFilesInDirectory( hStack, cSubDir, hFileIn, &inFind ); - FindClose( hFileIn ); - } - } - else - { - iNumFiles++; - strcpy( cName, cDir ); - strcpy( &(cName[strlen(cName)-3]), find.cFileName ); - CharLower( cName ); - hStack = Push( hStack, cName ); - } - find.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - fMore = FindNextFile( hFile, &find ); - } - FindClose( hFile ); - - // - // Okay, we have all the files in the stack, now put them in place. - // - gfs.uiNumFilesInDirectory = iNumFiles; - - gfs.pcFileNames = (STR8)MemAlloc( iNumFiles * FILENAME_LENGTH ); - - if ( gfs.pcFileNames ) - { - for ( i=0 ; icreation -// -//************************************************************************** - -INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *pcDir, HANDLE hFile, WIN32_FIND_DATA *pFind ) -{ - INT32 iNumFiles; - WIN32_FIND_DATA inFind; - BOOLEAN fMore; - CHAR cName[FILENAME_LENGTH], cDir[FILENAME_LENGTH]; - HANDLE hFileIn; - - fMore = TRUE; - iNumFiles = 0; - - while ( fMore ) - { - if ( pFind->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) - { - if ( strcmp( pFind->cFileName, "." ) != 0 && strcmp( pFind->cFileName, ".." ) != 0 ) - { - // a valid directory - recurse and find the files in that directory - - inFind.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - strcpy( cDir, pcDir ); - strcpy( &(cDir[strlen(cDir)-3]), pFind->cFileName ); - strcpy( &(cDir[strlen(cDir)]), "\\*.*\0" ); - hFileIn = FindFirstFile( cDir, &inFind ); - iNumFiles += GetFilesInDirectory( hStack, cDir, hFileIn, &inFind ); - FindClose( hFileIn ); - } - } - else - { - iNumFiles++; - strcpy( cName, pcDir ); - strcpy( &(cName[strlen(cName)-3]), pFind->cFileName ); - CharLower( cName ); - hStack = Push( hStack, cName ); - } - pFind->dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - fMore = FindNextFile( hFile, pFind ); - } - - return(iNumFiles); -} - BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ) { try diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index e5ba0854..cf38d7b4 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -25,7 +25,6 @@ #include "FileCat.h" -#include "Container.h" //************************************************************************** // @@ -163,9 +162,6 @@ BOOLEAN FileCheckEndOfFile( HWFILE hFile ); BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime ); -INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *pcDir, HANDLE hFile, WIN32_FIND_DATA *pFind ); - - // CompareSGPFileTimes() returns... // -1 if the First file time is less than second file time. ( first file is older ) diff --git a/Standard Gaming Platform/sgp.cpp b/Standard Gaming Platform/sgp.cpp index b3fe6e6d..e5f601ee 100644 --- a/Standard Gaming Platform/sgp.cpp +++ b/Standard Gaming Platform/sgp.cpp @@ -453,9 +453,6 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow) return FALSE; } - FastDebugMsg("Initializing Containers Manager"); - InitializeContainers(); - FastDebugMsg("Initializing Input Manager"); // Initialize the Input Manager if (InitializeInputManager() == FALSE) @@ -656,7 +653,6 @@ void ShutdownStandardGamingPlatform(void) ShutdownVideoManager(); ShutdownInputManager(); - ShutdownContainers(); ShutdownFileManager(); #ifdef EXTREME_MEMORY_DEBUGGING diff --git a/Standard Gaming Platform/vobject.h b/Standard Gaming Platform/vobject.h index c4964899..40a59f03 100644 --- a/Standard Gaming Platform/vobject.h +++ b/Standard Gaming Platform/vobject.h @@ -2,7 +2,6 @@ #define __VOBJECT_H #include "types.h" -#include "container.h" #include "himage.h" // ************************************************************************************ diff --git a/Standard Gaming Platform/vsurface.h b/Standard Gaming Platform/vsurface.h index 8564aab5..b6a7fa0c 100644 --- a/Standard Gaming Platform/vsurface.h +++ b/Standard Gaming Platform/vsurface.h @@ -2,7 +2,6 @@ #define __VSURFACE_H #include "types.h" -#include "container.h" #include "himage.h" #include "vobject.h" #include diff --git a/Tactical/Faces.cpp b/Tactical/Faces.cpp index a1647353..4759b4ac 100644 --- a/Tactical/Faces.cpp +++ b/Tactical/Faces.cpp @@ -8,7 +8,6 @@ #include "vsurface.h" #include "Render Dirty.h" #include "sysutil.h" - #include "container.h" #include "wcheck.h" #include "video.h" #include "vobject_blitters.h" diff --git a/Tactical/PATHAI.cpp b/Tactical/PATHAI.cpp index c8543b59..9bc43579 100644 --- a/Tactical/PATHAI.cpp +++ b/Tactical/PATHAI.cpp @@ -18,7 +18,6 @@ #include "Animation Cache.h" #include "Animation Data.h" #include "Animation Control.h" - #include "container.h" #include "interface.h" #include diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index d99e31bd..dacb8dfc 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -12,7 +12,6 @@ #include "Animation Cache.h" #include "Animation Data.h" #include "Animation Control.h" -#include "container.h" #define _USE_MATH_DEFINES // for C #include #include "pathai.h" diff --git a/Tactical/Soldier Tile.cpp b/Tactical/Soldier Tile.cpp index 4a3d7037..6b994eac 100644 --- a/Tactical/Soldier Tile.cpp +++ b/Tactical/Soldier Tile.cpp @@ -10,7 +10,6 @@ #include "Animation Cache.h" #include "Animation Data.h" #include "Animation Control.h" - #include "container.h" #include "pathai.h" #include "Random.h" #include "worldman.h" diff --git a/Tactical/bullets.cpp b/Tactical/bullets.cpp index 3548b30c..3d1e62a3 100644 --- a/Tactical/bullets.cpp +++ b/Tactical/bullets.cpp @@ -7,7 +7,6 @@ #include "renderworld.h" #include "vsurface.h" #include "sysutil.h" - #include "container.h" #include "wcheck.h" #include "video.h" #include "vobject_blitters.h" diff --git a/Utils/Event Pump.cpp b/Utils/Event Pump.cpp index c0567777..74576ef5 100644 --- a/Utils/Event Pump.cpp +++ b/Utils/Event Pump.cpp @@ -1,7 +1,6 @@ #include #include #include "sgp.h" -#include "container.h" #include "wcheck.h" #include "Event Pump.h" #include "Timer.h" diff --git a/Utils/Utils All.h b/Utils/Utils All.h index dd77c717..208f4990 100644 --- a/Utils/Utils All.h +++ b/Utils/Utils All.h @@ -30,7 +30,6 @@ #include #include #include -#include "container.h" #include "wcheck.h" #include "Event Manager.h" #include "Event Pump.h" @@ -108,4 +107,4 @@ //#include //#include //#include -#endif \ No newline at end of file +#endif diff --git a/aniviewscreen.cpp b/aniviewscreen.cpp index 8f05104d..638e67a2 100644 --- a/aniviewscreen.cpp +++ b/aniviewscreen.cpp @@ -11,7 +11,6 @@ #include "input.h" #include "font.h" #include "screenids.h" - #include "container.h" #include "overhead.h" #include "sysutil.h" #include "Font Control.h" From 02f733ce2f36648a1c3d14f2deb0a2b57518f49b Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:34:03 +0300 Subject: [PATCH 05/46] Remove CreateFileHandle() & DestroyFileHandle() --- Standard Gaming Platform/FileMan.cpp | 90 ---------------------------- 1 file changed, 90 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index ec348b16..91e270af 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -144,10 +144,7 @@ TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) //************************************************************************** void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ); - HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ); -HWFILE CreateFileHandle( HANDLE hRealFile, BOOLEAN fDatabaseFile ); -void DestroyFileHandle( HWFILE hFile ); //************************************************************************** // @@ -859,93 +856,6 @@ HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ) return(hRealFile); } -//************************************************************************** -// -// CreateFileHandle -// -// -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** -/* - - not needed anymore - -HWFILE CreateFileHandle( HANDLE hRealFile, BOOLEAN fDatabaseFile ) -{ - UINT32 i, uiOldNumHandles; - FMFileInfo *pNewFileInfo; - - Assert( !fDatabaseFile || (fDatabaseFile && gfs.fDBInitialized) ); - - // don't use 1st position - it'll confuse the users - for ( i=1 ; icreation -// -//************************************************************************** -/* -void DestroyFileHandle( HWFILE hFile ) -{ - if ( hFile < gfs.uiNumHandles && hFile ) - { - gfs.pFileInfo[hFile].hFileHandle = 0; - gfs.pFileInfo[hFile].hDBFile = 0; - } -} -*/ - BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ) { From 6c0b62cb42a06e0a5b872fede2f1103aed72befd Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:37:12 +0300 Subject: [PATCH 06/46] Remove W32toSGPFileFind() --- Standard Gaming Platform/FileMan.cpp | 61 ---------------------------- 1 file changed, 61 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 91e270af..ae437a73 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -143,7 +143,6 @@ TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) // //************************************************************************** -void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ); HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ); //************************************************************************** @@ -1004,66 +1003,6 @@ void GetFileClose( GETFILESTRUCT *pGFStruct ) file_iter = vfs::CVirtualFileSystem::Iterator(); } -void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ) -{ - UINT32 uiAttribMask; - - // Copy the filename - strcpy(pGFStruct->zFileName, pW32Struct->cFileName); - - // Get file size - if ( pW32Struct->nFileSizeHigh != 0 ) - pGFStruct->uiFileSize = 0xffffffff; - else - pGFStruct->uiFileSize = pW32Struct->nFileSizeLow; - - // Copy the file attributes - pGFStruct->uiFileAttribs = 0; - - for( uiAttribMask = 0x80000000; uiAttribMask > 0; uiAttribMask >>= 1) - { - switch( pW32Struct->dwFileAttributes & uiAttribMask ) - { - case FILE_ATTRIBUTE_ARCHIVE: - pGFStruct->uiFileAttribs |= FILE_IS_ARCHIVE; - break; - - case FILE_ATTRIBUTE_DIRECTORY: - pGFStruct->uiFileAttribs |= FILE_IS_DIRECTORY; - break; - - case FILE_ATTRIBUTE_HIDDEN: - pGFStruct->uiFileAttribs |= FILE_IS_HIDDEN; - break; - - case FILE_ATTRIBUTE_NORMAL: - pGFStruct->uiFileAttribs |= FILE_IS_NORMAL; - break; - - case FILE_ATTRIBUTE_READONLY: - pGFStruct->uiFileAttribs |= FILE_IS_READONLY; - break; - - case FILE_ATTRIBUTE_SYSTEM: - pGFStruct->uiFileAttribs |= FILE_IS_SYSTEM; - break; - - case FILE_ATTRIBUTE_TEMPORARY: - pGFStruct->uiFileAttribs |= FILE_IS_TEMPORARY; - break; - - case FILE_ATTRIBUTE_COMPRESSED: - pGFStruct->uiFileAttribs |= FILE_IS_COMPRESSED; - break; - - case FILE_ATTRIBUTE_OFFLINE: - pGFStruct->uiFileAttribs |= FILE_IS_OFFLINE; - break; - } - } -} - - BOOLEAN FileCopy(STR strSrcFile, STR strDstFile, BOOLEAN fFailIfExists) { From 62b8d272e671d7d749111a088f3b722f07700947 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:38:03 +0300 Subject: [PATCH 07/46] Remove GetHandleToRealFile() --- Standard Gaming Platform/FileMan.cpp | 44 ---------------------------- 1 file changed, 44 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index ae437a73..bc0d5442 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -143,8 +143,6 @@ TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) // //************************************************************************** -HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ); - //************************************************************************** // // Functions @@ -814,48 +812,6 @@ UINT32 FileGetSize( HWFILE hFile ) } -//************************************************************************** -// -// GetHandleToRealFile -// -// -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ) -{ - HANDLE hRealFile; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - *pfDatabaseFile = FALSE; - } - else - { - *pfDatabaseFile = TRUE; - hRealFile = (HANDLE) hFile; - } - - return(hRealFile); -} - - BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ) { try From eff1ccfe63370318b0c7c36db188f799ad065c26 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:45:44 +0300 Subject: [PATCH 08/46] Remove unused functions FileDebug() DirectoryExists() FileCopy() FileMove() --- Standard Gaming Platform/FileMan.cpp | 131 --------------------------- Standard Gaming Platform/FileMan.h | 6 -- 2 files changed, 137 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index bc0d5442..1c43fc2a 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -191,24 +191,6 @@ void ShutdownFileManager( void ) UnRegisterDebugTopic( TOPIC_FILE_MANAGER, "File Manager" ); } -//************************************************************************** -// -// FileDebug -// -// To set whether or not we should print debug info. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** - -void FileDebug( BOOLEAN f ) -{ -// gfs.fDebug = f; -} //************************************************************************** // @@ -844,37 +826,6 @@ BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory ) } -BOOLEAN DirectoryExists( STRING512 pcDirectory ) -{ - UINT32 uiAttribs; - DWORD uiLastError; - - uiAttribs = GetFileAttributes( pcDirectory ); - - if ( uiAttribs == 0xFFFFFFFF ) - { - // an error, make sure it's the right error - uiLastError = GetLastError(); - - if (uiLastError != ERROR_FILE_NOT_FOUND) - { - FastDebugMsg(String("DirectoryExists: ERROR - GetFileAttributes failed, error #%d on file %s", uiLastError, pcDirectory)); - } - } - else - { - // something's there, make sure it's a directory - if ( uiAttribs & FILE_ATTRIBUTE_DIRECTORY ) - { - return TRUE; - } - } - - // this could also mean that the name given is that of a file, or that an error occurred - return FALSE; -} - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Removes ALL FILES in the specified directory (and all subdirectories with their files if fRecursive is TRUE) // Use EraseDirectory() to simply delete directory contents without deleting the directory itself @@ -960,88 +911,6 @@ void GetFileClose( GETFILESTRUCT *pGFStruct ) } -BOOLEAN FileCopy(STR strSrcFile, STR strDstFile, BOOLEAN fFailIfExists) -{ - return(CopyFile(strSrcFile, strDstFile, fFailIfExists)); - -// Not needed, use Windows CopyFile -/* - HWFILE hFile; - UINT32 uiSize; - CHAR *pBuffer; - UINT32 uiBytesRead, uiBytesWritten; - - - // open source file - hFile = FileOpen(strSrcFile, FILE_ACCESS_READ, FALSE); - if (hFile == 0) - { - FastDebugMsg(String("FileCopy: FileOpen failed on Src file %s", strSrcFile)); - return(FALSE); - } - - // get its size - uiSize = FileGetSize(hFile); - if (uiSize == 0) - { - FastDebugMsg(String("FileCopy: size is 0, Src file %s", strSrcFile)); - FileClose(hFile); - return(FALSE); - } - - // allocate a buffer big enough to hold the entire file - pBuffer = MemAlloc(uiSize); - if (pBuffer == NULL) - { - FastDebugMsg(String("FileCopy: ERROR - MemAlloc pBuffer failed, size %d", uiSize)); - FileClose(hFile); - return(FALSE); - } - - // read the file into memory - if (!FileRead(hFile, pBuffer, uiSize, &uiBytesRead)) - { - FastDebugMsg(String("FileCopy: FileRead failed, file %s", strSrcFile)); - FileClose(hFile); - return(FALSE); - } - - // close source file - FileClose(hFile); - - - // open destination file - hFile = FileOpen(strDstFile, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE); - if (hFile == 0) - { - FastDebugMsg(String("FileCopy: FileOpen failed on Dst file %s", strDstFile)); - return(FALSE); - } - - // write buffer to the destination file - if (!FileWrite(hFile, pBuffer, uiSize, &uiBytesWritten)) - { - FastDebugMsg(String("FileCopy: FileWrite failed, file %s", strDstFile)); - FileClose(hFile); - return(FALSE); - } - - // close destination file - FileClose(hFile); - - - MemFree(pBuffer); - pBuffer = NULL; - return(TRUE); -*/ -} - -BOOLEAN FileMove(STR strOldName, STR strNewName) -{ - // rename - return(MoveFile(strOldName, strNewName)); -} - //Additions by Kris Morness BOOLEAN FileSetAttributes( STR strFilename, UINT32 uiNewAttribs ) { diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index cf38d7b4..e84f872f 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -102,7 +102,6 @@ extern "C" { extern BOOLEAN InitializeFileManager( STR strIndexFilename ); extern void ShutdownFileManager( void ); -extern void FileDebug( BOOLEAN f ); BOOLEAN FileExists( STR strFilename ); @@ -130,8 +129,6 @@ BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ); BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory ); BOOLEAN GetExecutableDirectory( STRING512 pcDirectory ); -BOOLEAN DirectoryExists( STRING512 pcDirectory ); - // WARNING: THESE DELETE ALL FILES IN THE DIRECTORY ( and all subdirectories if fRecursive is TRUE!! ) BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive); BOOLEAN EraseDirectory( STRING512 pcDirectory); @@ -148,9 +145,6 @@ BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct ); BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct ); void GetFileClose( GETFILESTRUCT *pGFStruct ); -BOOLEAN FileCopy(STR strSrcFile, STR strDstFile, BOOLEAN fFailIfExists); -BOOLEAN FileMove(STR strOldName, STR strNewName); - //Added by Kris Morness BOOLEAN FileSetAttributes( STR filename, UINT32 uiNewAttribs ); UINT32 FileGetAttributes( STR filename ); From c07f3f460bf4f8d6b55d89ddd65926262fb04818 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:59:28 +0300 Subject: [PATCH 09/46] Remove unused autosave and filetime functions --- SaveLoadGame.cpp | 63 --------------------- SaveLoadGame.h | 1 - Standard Gaming Platform/FileMan.cpp | 82 ---------------------------- Standard Gaming Platform/FileMan.h | 15 ----- 4 files changed, 161 deletions(-) diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index a013b455..dffa7337 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -9961,69 +9961,6 @@ void UpdateMercMercContractInfo() } } -INT8 GetNumberForAutoSave( BOOLEAN fLatestAutoSave ) -{ - CHAR zFileName1[MAX_PATH]; - CHAR zFileName2[MAX_PATH]; - HWFILE hFile; - BOOLEAN fFile1Exist, fFile2Exist; - SGP_FILETIME CreationTime1, LastAccessedTime1, LastWriteTime1; - SGP_FILETIME CreationTime2, LastAccessedTime2, LastWriteTime2; - - fFile1Exist = FALSE; - fFile2Exist = FALSE; - - - //The name of the file - sprintf( zFileName1, "%s\\Auto%02d.%S", gSaveDir, 0, pMessageStrings[ MSG_SAVEEXTENSION ] ); - sprintf( zFileName2, "%s\\Auto%02d.%S", gSaveDir, 1, pMessageStrings[ MSG_SAVEEXTENSION ] ); - - if( FileExists( zFileName1 ) ) - { - hFile = FileOpen( zFileName1, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - - GetFileManFileTime( hFile, &CreationTime1, &LastAccessedTime1, &LastWriteTime1 ); - - FileClose( hFile ); - - fFile1Exist = TRUE; - } - - if( FileExists( zFileName2 ) ) - { - hFile = FileOpen( zFileName2, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - - GetFileManFileTime( hFile, &CreationTime2, &LastAccessedTime2, &LastWriteTime2 ); - - FileClose( hFile ); - - fFile2Exist = TRUE; - } - - if( !fFile1Exist && !fFile2Exist ) - return( -1 ); - else if( fFile1Exist && !fFile2Exist ) - { - if( fLatestAutoSave ) - return( 0 ); - else - return( -1 ); - } - else if( !fFile1Exist && fFile2Exist ) - { - if( fLatestAutoSave ) - return( 1 ); - else - return( -1 ); - } - else - { - if( CompareSGPFileTimes( &LastWriteTime1, &LastWriteTime2 ) > 0 ) - return( 0 ); - else - return( 1 ); - } -} void HandleOldBobbyRMailOrders() { diff --git a/SaveLoadGame.h b/SaveLoadGame.h index a1f9664a..b1a36271 100644 --- a/SaveLoadGame.h +++ b/SaveLoadGame.h @@ -99,7 +99,6 @@ void GetBestPossibleSectorXYZValues( INT16 *psSectorX, INT16 *psSectorY, INT8 *p extern UINT32 guiLastSaveGameNum; // The end turn auto save number (0 = Auto00.sav, 1 = Auto01.sav) -INT8 GetNumberForAutoSave( BOOLEAN fLatestAutoSave ); /*CHRISL: This function is designed to allow reading the save game file one field at a time. We currently save structures by saving a block of memory, but variables are stored in memory so that they fit neatly into a WORD resulting in the program automatically adding some padding. This padding is saved diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 1c43fc2a..cd631004 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -911,76 +911,6 @@ void GetFileClose( GETFILESTRUCT *pGFStruct ) } -//Additions by Kris Morness -BOOLEAN FileSetAttributes( STR strFilename, UINT32 uiNewAttribs ) -{ - UINT32 uiFileAttrib = 0; - - if( uiNewAttribs & FILE_ATTRIBUTES_ARCHIVE ) - uiFileAttrib |= FILE_ATTRIBUTE_ARCHIVE; - - if( uiNewAttribs & FILE_ATTRIBUTES_HIDDEN ) - uiFileAttrib |= FILE_ATTRIBUTE_HIDDEN; - - if( uiNewAttribs & FILE_ATTRIBUTES_NORMAL ) - uiFileAttrib |= FILE_ATTRIBUTE_NORMAL; - - if( uiNewAttribs & FILE_ATTRIBUTES_OFFLINE ) - uiFileAttrib |= FILE_ATTRIBUTE_OFFLINE; - - if( uiNewAttribs & FILE_ATTRIBUTES_READONLY ) - uiFileAttrib |= FILE_ATTRIBUTE_READONLY; - - if( uiNewAttribs & FILE_ATTRIBUTES_SYSTEM ) - uiFileAttrib |= FILE_ATTRIBUTE_SYSTEM; - - if( uiNewAttribs & FILE_ATTRIBUTES_TEMPORARY ) - uiFileAttrib |= FILE_ATTRIBUTE_TEMPORARY; - - return SetFileAttributes( strFilename, uiFileAttrib ); -} - - -UINT32 FileGetAttributes( STR strFilename ) -{ - UINT32 uiAttribs = 0; - UINT32 uiFileAttrib = 0; - - uiAttribs = GetFileAttributes( strFilename ); - - if( uiAttribs == 0xFFFFFFFF ) - return( uiAttribs ); - - if( uiAttribs & FILE_ATTRIBUTE_ARCHIVE ) - uiFileAttrib |= FILE_ATTRIBUTES_ARCHIVE; - - if( uiAttribs & FILE_ATTRIBUTE_HIDDEN ) - uiFileAttrib |= FILE_ATTRIBUTES_HIDDEN; - - if( uiAttribs & FILE_ATTRIBUTE_NORMAL ) - uiFileAttrib |= FILE_ATTRIBUTES_NORMAL; - - if( uiAttribs & FILE_ATTRIBUTE_OFFLINE ) - uiFileAttrib |= FILE_ATTRIBUTES_OFFLINE; - - if( uiAttribs & FILE_ATTRIBUTE_READONLY ) - uiFileAttrib |= FILE_ATTRIBUTES_READONLY; - - if( uiAttribs & FILE_ATTRIBUTE_SYSTEM ) - uiFileAttrib |= FILE_ATTRIBUTES_SYSTEM; - - if( uiAttribs & FILE_ATTRIBUTE_TEMPORARY ) - uiFileAttrib |= FILE_ATTRIBUTES_TEMPORARY; - - if( uiAttribs & FILE_ATTRIBUTE_DIRECTORY ) - uiFileAttrib |= FILE_ATTRIBUTES_DIRECTORY; - - - - return( uiFileAttrib ); -} - - //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ) { @@ -1011,18 +941,6 @@ BOOLEAN FileCheckEndOfFile( HWFILE hFile ) } - -BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime ) -{ - return( FALSE ); -} - - -INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFileTime ) -{ - return( CompareFileTime( pFirstFileTime, pSecondFileTime ) ); -} - UINT32 FileSize(STR strFilename) { vfs::IBaseFile *pFile = getVFS()->getFile(vfs::Path(strFilename)); diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index e84f872f..1b21e8bc 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -145,24 +145,9 @@ BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct ); BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct ); void GetFileClose( GETFILESTRUCT *pGFStruct ); -//Added by Kris Morness -BOOLEAN FileSetAttributes( STR filename, UINT32 uiNewAttribs ); -UINT32 FileGetAttributes( STR filename ); - //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ); - - -BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime ); - - -// CompareSGPFileTimes() returns... -// -1 if the First file time is less than second file time. ( first file is older ) -// 0 First file time is equal to second file time. -// +1 First file time is greater than second file time ( first file is newer ). -INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFileTime ); - // One call comparison of file times, allowing for a certain leeway in cases where // files times may be slightly different due to SourceSafe of copying BOOLEAN FileIsOlderThanFile(CHAR8 *pcFileName1, CHAR8 *pcFileName2, UINT32 ulNumSeconds); From b7f974f41b7e1deec03e023fb64788da4bcc35ae Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:01:15 +0300 Subject: [PATCH 10/46] Remove unused AddSubdirectoryToPath() & FileIsOlderThanFile() --- Standard Gaming Platform/FileMan.cpp | 71 ---------------------------- Standard Gaming Platform/FileMan.h | 8 ---- 2 files changed, 79 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index cd631004..a127ee77 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -952,77 +952,6 @@ UINT32 FileSize(STR strFilename) } -//************************************************************************** -// -// AddSubdirectoryToPath -// -// Puts a subdirectory of the current working directory into the current -// task's system path. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 10June98:DB ->creation -// -//************************************************************************** -BOOLEAN AddSubdirectoryToPath(CHAR8 *pDirectory) -{ -CHAR8 *pSystemPath; -CHAR8 *pPath; -UINT32 uiPathLen; - - // Check for NULL - if(!pDirectory) - return(FALSE); - - // Check for zero length string - if(!strlen(pDirectory)) - return(FALSE); - - if((pSystemPath=(CHAR8 *)MemAlloc(_MAX_PATH))==NULL) - return(FALSE); - - memset(pSystemPath, 0, _MAX_PATH); - - if((pPath=(CHAR8 *)MemAlloc(_MAX_PATH))==NULL) - { - MemFree(pSystemPath); - return(FALSE); - } - - memset(pPath, 0, _MAX_PATH); - - // Builds a path to the directory with the SR DLL files. - _getcwd(pPath, _MAX_PATH); - uiPathLen=strlen(pPath); - if(uiPathLen) - uiPathLen--; - if(pPath[uiPathLen]!='\\') - strcat(pPath, "\\"); - - strcat(pPath, pDirectory); - - // Appends it to the path for the current task - if(GetEnvironmentVariable("PATH", pSystemPath, _MAX_PATH)) - { - strcat(pSystemPath, ";"); - strcat(pSystemPath, pPath); - SetEnvironmentVariable("PATH", pSystemPath); - MemFree(pSystemPath); - MemFree(pPath); - return(TRUE); - } - else - { - MemFree(pSystemPath); - MemFree(pPath); - return(FALSE); - } - -} - - UINT32 GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ) { STRING512 zExecDir; diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index 1b21e8bc..428b213b 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -148,14 +148,6 @@ void GetFileClose( GETFILESTRUCT *pGFStruct ); //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ); -// One call comparison of file times, allowing for a certain leeway in cases where -// files times may be slightly different due to SourceSafe of copying -BOOLEAN FileIsOlderThanFile(CHAR8 *pcFileName1, CHAR8 *pcFileName2, UINT32 ulNumSeconds); - - -BOOLEAN AddSubdirectoryToPath(CHAR8 *pDirectory); - - //Gets the amount of free space on the hard drive that the main executeablt is runnning from UINT32 GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ); From db0787b5a37116b7b686d9b0071690369f51da89 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:06:02 +0300 Subject: [PATCH 11/46] Remove unused functions GetFreeSpaceOnHardDriveWhereGameIsRunningFrom() GetFreeSpaceOnHardDrive() FileReadLine() <- non VFS version DoesUserHaveEnoughHardDriveSpace() --- SaveLoadGame.cpp | 15 ------- SaveLoadGame.h | 2 - Standard Gaming Platform/FileMan.cpp | 65 ---------------------------- Standard Gaming Platform/FileMan.h | 7 --- 4 files changed, 89 deletions(-) diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index dffa7337..7d8cc015 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -9683,21 +9683,6 @@ BOOLEAN SaveMeanwhileDefsFromSaveGameFile( HWFILE hFile ) return( TRUE ); } -BOOLEAN DoesUserHaveEnoughHardDriveSpace() -{ - UINT32 uiBytesFree=0; - - uiBytesFree = GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ); - - //check to see if there is enough hard drive space - if( uiBytesFree < REQUIRED_FREE_SPACE ) - { - return( FALSE ); - } - - return( TRUE ); -} - #ifdef JA2BETAVERSION void InitShutDownMapTempFileTest( BOOLEAN fInit, STR pNameOfFile, UINT8 ubSaveGameID ) diff --git a/SaveLoadGame.h b/SaveLoadGame.h index b1a36271..3cc011f6 100644 --- a/SaveLoadGame.h +++ b/SaveLoadGame.h @@ -93,8 +93,6 @@ BOOLEAN CopySavedSoldierInfoToNewSoldier( SOLDIERTYPE *pDestSourceInfo, SOLDIERT BOOLEAN SaveFilesToSavedGame( STR pSrcFileName, HWFILE hFile ); BOOLEAN LoadFilesFromSavedGame( STR pSrcFileName, HWFILE hFile ); -BOOLEAN DoesUserHaveEnoughHardDriveSpace(); - void GetBestPossibleSectorXYZValues( INT16 *psSectorX, INT16 *psSectorY, INT8 *pbSectorZ ); diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index a127ee77..6ab2b70e 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -470,22 +470,6 @@ BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest ) return FALSE; } -BOOLEAN FileReadLine( HWFILE hFile, STR8 pDest, UINT32 uiDestSize, UINT32 *puiBytesRead ) -{ - std::string sBuffer; - BOOLEAN result = (pDest != NULL) && FileReadLine( hFile, &sBuffer ); - if ( result ) - { - if ( puiBytesRead ) - *puiBytesRead = sBuffer.length(); - - UINT32 uiCountToCopy = min( sBuffer.length(), uiDestSize - 1 ); - sBuffer.copy( pDest, uiCountToCopy ); - pDest[uiCountToCopy] = '\0'; // method copy() does not put a null-terminator - } - return result; -} - //************************************************************************** // // FileWrite @@ -952,55 +936,6 @@ UINT32 FileSize(STR strFilename) } -UINT32 GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ) -{ - STRING512 zExecDir; - STRING512 zDrive; - STRING512 zDir; - STRING512 zFileName; - STRING512 zExt; - - UINT32 uiFreeSpace = 0; - - GetExecutableDirectory( zExecDir ); - - //get the drive letter from the exec dir - _splitpath( zExecDir, zDrive, zDir, zFileName, zExt); - - sprintf( zDrive, "%s\\", zDrive ); - - uiFreeSpace = GetFreeSpaceOnHardDrive( zDrive ); - - return( uiFreeSpace ); -} - - - - -UINT32 GetFreeSpaceOnHardDrive( STR pzDriveLetter ) -{ - UINT32 uiBytesFree=0; - - UINT32 uiSectorsPerCluster=0; - UINT32 uiBytesPerSector=0; - UINT32 uiNumberOfFreeClusters=0; - UINT32 uiTotalNumberOfClusters=0; - - if( !GetDiskFreeSpace( pzDriveLetter, (LPDWORD) &uiSectorsPerCluster, (LPDWORD) &uiBytesPerSector, - (LPDWORD) &uiNumberOfFreeClusters, (LPDWORD) &uiTotalNumberOfClusters ) ) - { - UINT32 uiLastError = GetLastError(); - char zString[1024]; - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, uiLastError, 0, zString, 1024, NULL); - - return( TRUE ); - } - - uiBytesFree = uiBytesPerSector * uiNumberOfFreeClusters * uiSectorsPerCluster; - - return( uiBytesFree ); -} - // Flugente: simple wrapper to check whether an audio file in mp3/ogg/wav format exists BOOLEAN SoundFileExists( STR strFilename, STR zFoundFilename ) { diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index 428b213b..ef77be56 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -113,7 +113,6 @@ extern void FileClose( HWFILE ); extern BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead ); extern BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest ); -extern BOOLEAN FileReadLine( HWFILE hFile, STR8 pDest, UINT32 uiDestSize, UINT32 *puiBytesRead ); extern BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten ); extern BOOLEAN FileLoad( STR filename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead ); @@ -148,12 +147,6 @@ void GetFileClose( GETFILESTRUCT *pGFStruct ); //returns true if at end of file, else false BOOLEAN FileCheckEndOfFile( HWFILE hFile ); -//Gets the amount of free space on the hard drive that the main executeablt is runnning from -UINT32 GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ); - -//Gets the free hard drive space from the drive letter passed in. It has to be the root dir. ( eg. c:\ ) -UINT32 GetFreeSpaceOnHardDrive( STR pzDriveLetter ); - // Flugente: simple wrapper to check whether an audio file in mp3/ogg/wav format exists BOOLEAN SoundFileExists( STR strFilename, STR zFoundFilename ); From 1483f15832c0349c5e72b038eb15f9634a6cae58 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:08:48 +0300 Subject: [PATCH 12/46] Remove unused globals --- Standard Gaming Platform/FileMan.cpp | 5 ----- Standard Gaming Platform/FileMan.h | 4 ---- 2 files changed, 9 deletions(-) diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp index 6ab2b70e..f392d6d8 100644 --- a/Standard Gaming Platform/FileMan.cpp +++ b/Standard Gaming Platform/FileMan.cpp @@ -132,11 +132,6 @@ HANDLE hFindInfoHandle[20] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; -// Snap: At program launch we build two directory catalogues: -// one for the default Data directory, the other for the custom Data directory. -TFileCat gDefaultDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) -TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) - //************************************************************************** // // Function Prototypes diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index ef77be56..8305303a 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -83,10 +83,6 @@ typedef FILETIME SGP_FILETIME; // //************************************************************************** -// Snap: At program launch we build two directory catalogues: -// one for the default Data directory, the other for the custom Data directory. -extern TFileCat gDefaultDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) -extern TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) //************************************************************************** // From 5a7ef1930fa12b35ce88e75fa2d9fded2402ec33 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:10:34 +0300 Subject: [PATCH 13/46] Remove unused defines --- Standard Gaming Platform/FileMan.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index 8305303a..ee9b68f4 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -60,17 +60,6 @@ #define FILE_IS_OFFLINE 256 - -//File Attributes settings -#define FILE_ATTRIBUTES_ARCHIVE FILE_ATTRIBUTE_ARCHIVE -#define FILE_ATTRIBUTES_HIDDEN FILE_ATTRIBUTE_HIDDEN -#define FILE_ATTRIBUTES_NORMAL FILE_ATTRIBUTE_NORMAL -#define FILE_ATTRIBUTES_OFFLINE FILE_ATTRIBUTE_OFFLINE -#define FILE_ATTRIBUTES_READONLY FILE_ATTRIBUTE_READONLY -#define FILE_ATTRIBUTES_SYSTEM FILE_ATTRIBUTE_SYSTEM -#define FILE_ATTRIBUTES_TEMPORARY FILE_ATTRIBUTE_TEMPORARY -#define FILE_ATTRIBUTES_DIRECTORY FILE_ATTRIBUTE_DIRECTORY - // Snap, Kaiden: This define duplicates a standard MFC define // Added to resolve some intractable issue with MSVC6 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) From d43a597423213aef22206435959e6001ada05f14 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:18:52 +0300 Subject: [PATCH 14/46] Remove commented out ifdefs --- Standard Gaming Platform/FileMan.h | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index ee9b68f4..5fac1d92 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -78,12 +78,6 @@ typedef FILETIME SGP_FILETIME; // Function Prototypes // //************************************************************************** -/* -#ifdef __cplusplus -extern "C" { -#endif -*/ - extern BOOLEAN InitializeFileManager( STR strIndexFilename ); extern void ShutdownFileManager( void ); @@ -134,11 +128,4 @@ BOOLEAN FileCheckEndOfFile( HWFILE hFile ); // Flugente: simple wrapper to check whether an audio file in mp3/ogg/wav format exists BOOLEAN SoundFileExists( STR strFilename, STR zFoundFilename ); - -/* -#ifdef __cplusplus -} -#endif -*/ - #endif From 5b635784cd11b1941a841062e28f825909afc590 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:29:15 +0300 Subject: [PATCH 15/46] Remove FileCat.cpp & .h Not used anywhere in the code. Moved ChompSlash from FileCat.cpp to image.cpp, as the only two references besides ones in filecat.cpp for the function were in there. The references are inside an #ifdef 0 block so they are not compiled currently, but this should prevent them from not working IF we ever enable them --- Standard Gaming Platform/CMakeLists.txt | 1 - Standard Gaming Platform/FileCat.cpp | 100 ------------------------ Standard Gaming Platform/FileCat.h | 48 ------------ Standard Gaming Platform/FileMan.h | 2 - ext/export/src/export/sti/Image.cpp | 11 +++ 5 files changed, 11 insertions(+), 151 deletions(-) delete mode 100644 Standard Gaming Platform/FileCat.cpp delete mode 100644 Standard Gaming Platform/FileCat.h diff --git a/Standard Gaming Platform/CMakeLists.txt b/Standard Gaming Platform/CMakeLists.txt index 70404804..f56cf667 100644 --- a/Standard Gaming Platform/CMakeLists.txt +++ b/Standard Gaming Platform/CMakeLists.txt @@ -9,7 +9,6 @@ set(SGPSrc "${CMAKE_CURRENT_SOURCE_DIR}/DirectDraw Calls.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/DirectX Common.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/English.cpp" -"${CMAKE_CURRENT_SOURCE_DIR}/FileCat.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/FileMan.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Flic.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Font.cpp" diff --git a/Standard Gaming Platform/FileCat.cpp b/Standard Gaming Platform/FileCat.cpp deleted file mode 100644 index a977d597..00000000 --- a/Standard Gaming Platform/FileCat.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// -// Snap: Implementation of the TFileCat class -// -#include "FileCat.h" -#include "readdir.h" - - -// Remove a slash or backslash (if any) from the end of a string -void ChompSlash(std::string& s) -{ - if ( s.empty() ) return; - - if ( *s.rbegin() == '\\' || *s.rbegin() == '/' ) { - s.erase( s.length() - 1 ); - } -} - - -// Build a new file catalogue by recursively traversing the root directory -void TFileCat::NewCat(std::string root) -{ - fRootDir = root; - ChompSlash(fRootDir); - - fFileCat.clear(); - - TraverseDir(fRootDir); -} - - -// Look for a given file in the catalogue -// Unless pathIncludesRoot == true, will prepend the root directory to path -bool TFileCat::FindFile(std::string path, bool pathIncludesRoot) const -{ - if (pathIncludesRoot) return fFileCat.find(path) != fFileCat.end(); - else return fFileCat.find(fRootDir + '\\' + path) != fFileCat.end(); -} - - -// Delete a given file from the catalogue -// Unless pathIncludesRoot == true, will prepend the root directory to path -size_t TFileCat::RemoveFile(std::string path, bool pathIncludesRoot) -{ - if (pathIncludesRoot) return fFileCat.erase(path); - else return fFileCat.erase(fRootDir + '\\' + path); -} - - -// Delete all files from a given directory in the catalogue -// Unless pathIncludesRoot == true, will prepend the root directory to path -size_t TFileCat::RemoveDir(std::string dir, bool pathIncludesRoot) -{ - if ( !pathIncludesRoot ) dir = fRootDir + '\\' + dir; - ChompSlash(dir); - std::string dirlower = dir + '\\'; - std::string dirupper = dir + char('\\'+1); - - TCatalogue::iterator upper = fFileCat.upper_bound(dirupper); - TCatalogue::iterator lower; - - int deleted = 0; - - while ( ( lower = fFileCat.lower_bound(dirlower) ) != upper) { - fFileCat.erase(lower); - deleted++; - } - - return deleted; -} - - -// Recursively traverse a directory, adding regular files to the catalogue -void TFileCat::TraverseDir(std::string dir, int depth) -{ - using std::string; - static string dot( "."); - static string dotdot( ".."); - static string svn( ".svn"); - - if (!dir.empty()) dir += '\\'; - - TReadDir readDir((dir + "*").c_str()); - - char const* fileName; - unsigned attrib; - - while ( readDir.NextFile(fileName, attrib) ) { - if (dot == fileName || dotdot == fileName || svn == fileName) continue; - - string fullPath = dir + fileName; - - if (attrib & FILE_ATTRIBUTE_DIRECTORY) { - if (depth < 0) TraverseDir(fullPath); - else if (depth > 0) TraverseDir(fullPath, depth-1); - } - else { - fFileCat.insert(fullPath); - } - } -} diff --git a/Standard Gaming Platform/FileCat.h b/Standard Gaming Platform/FileCat.h deleted file mode 100644 index 38d1fc27..00000000 --- a/Standard Gaming Platform/FileCat.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Snap: Declaration of the TFileCat class -// -// This class catalogues files in a directory and all its subdirectories -// -#ifndef FILECAT_H -#define FILECAT_H - -#include "stringicmp.h" -#include -#include - - -class TFileCat { -public: - - TFileCat(std::string root) { NewCat(root); } - TFileCat() {} - - // Build a new file catalogue by recursively traversing the root directory - void NewCat(std::string root); - - std::string GetRootDir() const { return fRootDir; } - - // Look for a given file in the catalogue - // Unless pathIncludesRoot == true, will prepend the root directory to path - bool FindFile(std::string path, bool pathIncludesRoot = false) const; - - // Delete a given file from the catalogue - // Unless pathIncludesRoot == true, will prepend the root directory to path - size_t RemoveFile(std::string path, bool pathIncludesRoot = false); - - // Delete all files from a given directory in the catalogue - // Unless pathIncludesRoot == true, will prepend the root directory to path - size_t RemoveDir(std::string dir, bool pathIncludesRoot = false); - -private: - - typedef std::set TCatalogue; - - std::string fRootDir; - TCatalogue fFileCat; - - // Recursively traverse a directory, adding regular files to the catalogue - void TraverseDir(std::string dir, int depth = -1); -}; - -#endif // FILECAT_H diff --git a/Standard Gaming Platform/FileMan.h b/Standard Gaming Platform/FileMan.h index 5fac1d92..bc860fc8 100644 --- a/Standard Gaming Platform/FileMan.h +++ b/Standard Gaming Platform/FileMan.h @@ -20,10 +20,8 @@ //************************************************************************** #include "types.h" - #include "Windows.h" -#include "FileCat.h" //************************************************************************** diff --git a/ext/export/src/export/sti/Image.cpp b/ext/export/src/export/sti/Image.cpp index cc719d69..2db90738 100644 --- a/ext/export/src/export/sti/Image.cpp +++ b/ext/export/src/export/sti/Image.cpp @@ -406,7 +406,18 @@ vfs::Path CreateFileName(vfs::Path const& sOutPathName, vfs::Path const& sFileNa outPath += vfs::Path(fullpath.str()); return outPath; } + #if 0 +// Remove a slash or backslash (if any) from the end of a string +void ChompSlash(std::string& s) +{ + if (s.empty()) return; + + if (*s.rbegin() == '\\' || *s.rbegin() == '/') { + s.erase(s.length() - 1); + } +} + bool CImage::WriteAsBMPs(vfs_string sOutPathName) { if(!this->LoadData()) From 2849590ef28a11f2ed90696c38f23893d8496ac8 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:36:23 +0300 Subject: [PATCH 16/46] Remove readdir.cpp & h Unused --- Standard Gaming Platform/CMakeLists.txt | 1 - Standard Gaming Platform/readdir.cpp | 22 -------------------- Standard Gaming Platform/readdir.h | 27 ------------------------- 3 files changed, 50 deletions(-) delete mode 100644 Standard Gaming Platform/readdir.cpp delete mode 100644 Standard Gaming Platform/readdir.h diff --git a/Standard Gaming Platform/CMakeLists.txt b/Standard Gaming Platform/CMakeLists.txt index f56cf667..c39224f5 100644 --- a/Standard Gaming Platform/CMakeLists.txt +++ b/Standard Gaming Platform/CMakeLists.txt @@ -24,7 +24,6 @@ set(SGPSrc "${CMAKE_CURRENT_SOURCE_DIR}/PCX.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/PngLoader.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Random.cpp" -"${CMAKE_CURRENT_SOURCE_DIR}/readdir.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/RegInst.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/sgp.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/sgp_logger.cpp" diff --git a/Standard Gaming Platform/readdir.cpp b/Standard Gaming Platform/readdir.cpp deleted file mode 100644 index 57a8c852..00000000 --- a/Standard Gaming Platform/readdir.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// -// Snap: Implementation of the TReadDir class -// This class reads the contents of a directory file-by-file -// -#include "readdir.h" - -TReadDir::TReadDir(char const* searchPattern) -{ - fSearchHandle = FindFirstFile(searchPattern, &fFileInfo); - fFirstRequest = true; -} - - -bool TReadDir::NextFile(char const* &fileName, unsigned &attrib) -{ - if (fSearchHandle == INVALID_HANDLE_VALUE) return false; - if (fFirstRequest) fFirstRequest = false; - else if ( !FindNextFile(fSearchHandle, &fFileInfo) ) return false; - fileName = fFileInfo.cFileName; - attrib = fFileInfo.dwFileAttributes; - return true; -} diff --git a/Standard Gaming Platform/readdir.h b/Standard Gaming Platform/readdir.h deleted file mode 100644 index b98ebae1..00000000 --- a/Standard Gaming Platform/readdir.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Snap: Declaration of the TReadDir class -// This class reads the contents of a directory file-by-file -// -#ifndef READDIR_H -#define READDIR_H - -#include - -class TReadDir { -public: - - TReadDir(char const* searchPattern); - - ~TReadDir() { FindClose(fSearchHandle); } - - bool NextFile(char const* &fileName, unsigned &attrib); - -private: - - HANDLE fSearchHandle; - WIN32_FIND_DATA fFileInfo; - bool fFirstRequest; -}; - - -#endif // #ifndef READDIR_H \ No newline at end of file From 58a682db89e693f8281880d15c06f2f3ab725f8e Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:42:09 +0300 Subject: [PATCH 17/46] Remove flic.cpp & h Not used anywhere and even inside the .cpp functions such as FlicPlay() had everything commented out and replaced with "return 1" --- Standard Gaming Platform/CMakeLists.txt | 1 - Standard Gaming Platform/Flic.cpp | 1696 ----------------------- Standard Gaming Platform/flic.h | 224 --- 3 files changed, 1921 deletions(-) delete mode 100644 Standard Gaming Platform/Flic.cpp delete mode 100644 Standard Gaming Platform/flic.h diff --git a/Standard Gaming Platform/CMakeLists.txt b/Standard Gaming Platform/CMakeLists.txt index c39224f5..4d0137a5 100644 --- a/Standard Gaming Platform/CMakeLists.txt +++ b/Standard Gaming Platform/CMakeLists.txt @@ -10,7 +10,6 @@ set(SGPSrc "${CMAKE_CURRENT_SOURCE_DIR}/DirectX Common.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/English.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/FileMan.cpp" -"${CMAKE_CURRENT_SOURCE_DIR}/Flic.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Font.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/himage.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/impTGA.cpp" diff --git a/Standard Gaming Platform/Flic.cpp b/Standard Gaming Platform/Flic.cpp deleted file mode 100644 index 7d278a25..00000000 --- a/Standard Gaming Platform/Flic.cpp +++ /dev/null @@ -1,1696 +0,0 @@ -//************************************************************************** -// -// Filename : flic.c -// -// Purpose : Display System for .flc and .fli Flic Files -// -// This program is derived from the program decribed in the article "The -// Flic File Format" on page 18 of the March 1993 edition of Dr. Dobb's -// Journal. It was restructured from the top down to meet the -// requirements of Sir-Tech. The high level routines were designed to -// provided easy integration with existing applications. Except for a few -// identifiers, the low level routines were not modified. -// -// All of the code for these routines in contained in this file and the -// file "flic.h". -// -// Modification history : -// -// 06-09-94:??? - Creation -// ???:David Smoth - ??? -// ???:Bret Rowdon for RIO/GORGE - added 640x480 SVGA support -// 05-11jun96:HJH - added routines for bitmap use, and -// other utilities -// 08-May-97 ARM Adapted for Win95 Standard Gaming Platform -// -//************************************************************************** - -//************************************************************************** -// -// Includes -// -//************************************************************************** - -#include -#include "flic.h" -#include "windows.h" -#include "types.h" -#include "wcheck.h" - -//************************************************************************** -// -// Variables -// -//************************************************************************** - -//Flic flic; -char pcxbuf[(640*480)]; -char FlicPal[768]; - -//extern char buffer[(640*480)]; -//extern char buffer2[(640*480)]; - -//************************************************************************** -// -// Function prototypes. -// -//************************************************************************** - -static ErrCode flic_next_frame(Flic *flic, BOOL fDecode); - -//************************************************************************** -// -// Functions -// -//************************************************************************** - -//************************************************************************** -// -// Low level Functions -// -//************************************************************************** - -//************************************************************************** -// -// screen_put_dot -// -// Set one dot. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_put_dot(FlicScreen *s, int x, int y, Pixel color) -{ - // First clip it. - if (x < 0 || y < 0 || x >= s->width || y >= s->height) - return; - - // Then set it. - s->pixels[(unsigned)(s->height-y-1) * s->width + x] = color; -} - -//************************************************************************** -// -// line_clip -// -// Clip a horizontal line segment so that it fits on the screen. -// Return FALSE if clipped out entirely. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static Boolean line_clip(FlicScreen *s, int *px, int *py, int *pwidth) -{ - int x = *px; - int y = *py; - int width = *pwidth; - int xend = x + width; - - if (y < 0 || y >= s->height || xend < 0 || x >= s->width) - return FALSE; /* Clipped off screen. */ - if (x < 0) - { - *pwidth = width = width + x; /* and shortens width. */ - *px = 0; - } - if (xend > s->width) - { - *pwidth = width = width - (xend - s->width); - } - if (width < 0) - return FALSE; - return TRUE; -} - -//************************************************************************** -// -// oldscreen_copy_seg -// -// Copy pixels from memory into screen. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static void oldscreen_copy_seg(FlicScreen *s, int x, int y, Pixel *pixels, int count) -{ - Pixel *pt; - //int xend; - int unclipped_x = x; - int dx; - - // First let's do some clipping. - if (!line_clip(s, &x, &y, &count)) - return; - - dx = x - unclipped_x; // Clipping change in start position. - if (dx != 0) - pixels += dx; // Advance over clipped pixels. - - // Calculate start screen address. - //pt = s->pixels + (unsigned)y * (unsigned)s->width + (unsigned)x; - pt = s->pixels + (unsigned)(s->height-y-1) * (unsigned)s->width + (unsigned)x; - - // Copy pixels to display. - while (--count >= 0) - *pt++ = *pixels++; -} - -//************************************************************************** -// -// screen_repeat_one -// -// Draw a horizontal line of a solid color -// -// Parameter List : -// -// FlicScreen *s -> screen to write to -// int x -> x position to write to -// int y -> y position to write to -// Pixel color -> colour to write -// int count -> how many times to write -// -// Return Value : -// -// Modification history : -// -// 01jun96:HJH -> reversed the screen up and down so that the -// bitmaps wouldn't come out upside down (I put in -// the "s->height -") -// -//************************************************************************** - -static void screen_repeat_one(FlicScreen *s, int x, int y, Pixel color, int count) -{ - Pixel *pt; - - // First let's do some clipping. - if (!line_clip(s, &x, &y, &count)) - return; - - // Calculate start screen address. - pt = s->pixels + (unsigned)(s->height-y-1) * (unsigned)s->width + (unsigned)x; - - // Repeat pixel on display. - while (--count >= 0) - *pt++ = color; -} - -//************************************************************************** -// -// screen_repeat_two -// -// Repeat 2 pixels count times on screen. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_repeat_two(FlicScreen *s, int x, int y, Pixels2 pixels2, int count) -{ - Pixels2 *pt; - int is_odd; - - // First let's do some clipping. - count <<= 1; // Convert from word to pixel count. - if (!line_clip(s, &x, &y, &count)) - return; - is_odd = (count&1); // Did it turn odd after clipping? Ack! - count >>= 1; // Convert back to word count. - - // Calculate start screen address. - pt = (Pixels2 *)(s->pixels + (unsigned)(s->height-y-1) * (unsigned)s->width + (unsigned)x); - - while (--count >= 0) // Go set screen 2 pixels at a time. - *pt++ = pixels2; - - if (is_odd) // Deal with pixel at end of screen if needed. - { - Pixel *end = (Pixel *)pt; - *end = pixels2.pixels[0]; - } -} - -//************************************************************************** -// -// screen_put_colors -// -// Set count colors in color map starting at start. RGB values -// go from 0 to 255. -// -// Parameter List : -// -// FlicScreen *s -> screen data -// int start -> start position -// Colour *colors -> the colors, of course -// int count -> how many -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_put_colors(FlicScreen *s, int start, Colour *colors, int count) -{ - int end = start + count; - int ix; - - for (ix = start; ix < end; ++ix) - { - FlicPal[ix*3]=colors->r>>2; - FlicPal[ix*3+1]=colors->g>>2; - FlicPal[ix*3+2]=colors->b>>2; - ++colors; - } -} - -//************************************************************************** -// -// screen_put_colors_64 -// -// Set count colors in color map starting at start. RGB values -// go from 0 to 64. */ -// -// Parameter List : -// -// FlicScreen *s -> screen data -// int start -> start position -// Colour *colors -> the colors, of course -// int count -> how many -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_put_colors_64(FlicScreen *s, int start, Colour *colors, int count) -{ - int end = start + count; - int ix; - - for (ix = start; ix < end; ++ix) - { - FlicPal[ix*3]=colors->r; - FlicPal[ix*3+1]=colors->g; - FlicPal[ix*3+2]=colors->b; - - ++colors; - } -} - -//************************************************************************** -// -// decode_byte_run -// -// Byte-run-length decompression. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_byte_run(Uchar *data, Flic *flic) -{ - int x,y; - int width = flic->head.width; - int height = flic->head.height; - int psize; // was char -> HJH - Char *cpt = (Char *)data; - int end; - - y = flic->yoff; - end = flic->xoff + width; - while (--height >= 0) - { - x = flic->xoff; - cpt += 1; /* skip over obsolete opcount byte */ - psize = 0; - while ((x+=psize) < end) - { - psize = (char)(*cpt++); - if (psize >= 0) - { - screen_repeat_one(&flic->screen, x, y, *cpt++, psize); - } - else - { - psize = -psize; - oldscreen_copy_seg(&(flic->screen),(long) x,(long) y, (unsigned char *)cpt, (long)psize); - cpt += psize; - } - } - y++; - } -} - -//************************************************************************** -// -// decode_delta_fli -// -// Fli style delta decompression. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_delta_fli(Uchar *data, Flic *flic) -{ - int xorg = flic->xoff; - int yorg = flic->yoff; - Short *wpt = (Short *)data; - Uchar *cpt = (Uchar *)(wpt + 2); - int x,y; - Short lines; - Uchar opcount; - Char psize; - - y = yorg + *wpt++; - lines = *wpt; - while (--lines >= 0) - { - x = xorg; - opcount = *cpt++; - while (opcount > 0) - { - x += *cpt++; - psize = *cpt++; - if (psize < 0) - { - psize = -psize; - screen_repeat_one(&flic->screen, x, y, *cpt++, psize); - x += psize; - opcount-=1; - } - else - { - oldscreen_copy_seg(&(flic->screen), (long)x, (long)y, (unsigned char *)cpt,(long) psize); - cpt += psize; - x += psize; - opcount -= 1; - } - } - y++; - } -} - -//************************************************************************** -// -// decode_delta_flc -// -// Flc-style delta decompression. The data is word oriented though -// a lot of the control info (how to skip, how many words to -// copy) are byte oriented still to save space. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_delta_flc(Uchar *data, Flic *flic) -{ - int xorg = flic->xoff; - int yorg = flic->yoff; - int width = flic->head.width; - int x,y; - Short lp_count; - Short opcount; - int psize; - union {Short *w; Uchar *ub; Char *b; Pixels2 *p2;} wpt; - int lastx; - - - lastx = xorg + width - 1; - wpt.ub = data; - lp_count = *wpt.w++; - y = yorg; - goto LPACK; - -SKIPLINES: /* Advance over some lines. */ - y -= opcount; - -LPACK: /* do next line */ - if ((opcount = *wpt.w++) >= 0) - goto DO_SS2OPS; - if( ((Ushort)opcount) & 0x4000) /* skip lines */ - goto SKIPLINES; - screen_put_dot(&flic->screen,(Uchar)opcount,lastx,(Pixel)y); /* put dot at eol with low byte */ - if((opcount = *wpt.w++) == 0) - { - ++y; - if (--lp_count > 0) - goto LPACK; - goto OUTT; - } -DO_SS2OPS: - x = xorg; - -PPACK: /* do next packet */ - x += *wpt.ub++; - psize = *wpt.b++; - if ((psize += psize) >= 0) - { - oldscreen_copy_seg(&(flic->screen), (long)x, (long)y, (unsigned char *)wpt.ub,(long) psize); - x += psize; - wpt.ub += psize; - if (--opcount != 0) - goto PPACK; - ++y; - if (--lp_count > 0) - goto LPACK; - } - else - { - psize = -psize; - screen_repeat_two(&flic->screen, x, y, *wpt.p2++, psize>>1); - x += psize; - if (--opcount != 0) - goto PPACK; - ++y; - if (--lp_count > 0) - goto LPACK; - } -OUTT: - return; -} - -//************************************************************************** -// -// decode_black -// -// Decode a BLACK chunk. Set frame to solid color 0 one -// line at a time. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_black(Uchar *data, Flic *flic) -{ - Pixels2 black; - int i; - int height = flic->head.height; - int width = flic->head.width; - int x = flic->xoff; - int y = flic->yoff; - - black.pixels[0] = black.pixels[1] = 0; - for (i=0; iscreen, x, y+i, black, width/2); - if (width & 1) /* if odd set last pixel */ - screen_put_dot(&flic->screen, x+width-1, y+i, 0); - } -} - -//************************************************************************** -// -// decode_literal -// -// Decode a LITERAL chunk. Just copy data to screen one line at -// a time. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_literal(Uchar *data, Flic *flic) -{ - int i; - int height = flic->head.height; - int width = flic->head.width; - int x = flic->xoff; - int y = flic->yoff; - - for (i=0; iscreen),(long) x,(long)(y+i), (unsigned char *)data,(long) width); - data += width; - } -} - - -typedef void ColorOut(FlicScreen *s, int start, Colour *colors, int count); - /* This is the type of output parameter to our decode_color below. - * Not coincedently screen_put_color is of this type. */ - - -//************************************************************************** -// -// decode_color -// -// Decode color map. Put results into output. The two color -// compressions are identical except for whether the RGB values -// are 0-63 or 0-255. Passing in an output that does the appropriate -// shifting on the way to the real pallete lets us use the same -// code for both COLOR_64 and COLOR_256 compression. -// -// Parameter List : -// -// Uchar *data -> data to decode -// Flic *flic -> the flic -// ColorOut *output -> place to put decoded data -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_color(Uchar *data, Flic *flic, ColorOut *output) -{ - int start = 0; - Uchar *cbuf = (Uchar *)data; - Short *wp = (Short *)cbuf; - Short ops; - int count; - - ops = *wp; - cbuf += sizeof(*wp); - while (--ops >= 0) - { - start += *cbuf++; - if ((count = *cbuf++) == 0) - count = 256; - (*output)(&flic->screen, start, (Colour *)cbuf, count); - cbuf += 3*count; - start += count; - } -} - -//************************************************************************** -// -// decode_color_256 -// -// Decode COLOR_256 chunk. -// -// Parameter List : -// -// Uchar *data -> data to decode -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_color_256(Uchar *data, Flic *flic) -{ - decode_color(data, flic, screen_put_colors); -} - -//************************************************************************** -// -// decode_color_64 -// -// Decode COLOR_64 chunk. -// -// Parameter List : -// -// Uchar *data -> data to decode -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_color_64(Uchar *data, Flic *flic) -{ - decode_color(data, flic, screen_put_colors_64); -} - -//************************************************************************** -// -// decode_frame -// -// Decode a frame that is in memory already into screen. -// Here we just loop through each chunk calling appropriate -// chunk decoder. -// -// Parameter List : -// -// Flic *flic -> the flic -// FrameHead *frame -> info about the frame -// Uchar *data -> data to decode -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static ErrCode decode_frame(Flic *flic, FrameHead *frame, Uchar *data) -{ - int i; - ChunkHead *chunk; - - for (i=0; ichunks; ++i) - { - chunk = (ChunkHead *)data; - data += chunk->size; - switch (chunk->type) - { - case COLOR_256: - if (flic->screen.change_palette) - //decode_color_256((Uchar *)(chunk+1), flic); - decode_color_256( (((Uchar *)chunk) + 4 ), flic); - break; - case DELTA_FLC: - decode_delta_flc((Uchar *)(chunk+1), flic); - break; - case COLOR_64: - if (flic->screen.change_palette) - decode_color_64((Uchar *)(chunk+1), flic); - break; - case DELTA_FLI: - decode_delta_fli((Uchar *)(chunk+1), flic); - break; - case BLACK_FRAME: - decode_black((Uchar *)(chunk+1), flic); - break; - case BYTE_RUN: - decode_byte_run((Uchar *)(chunk+1), flic); - break; - case LITERAL: - decode_literal((Uchar *)(chunk+1), flic); - break; - default: - break; - } - } - return 0; -} - -static ErrCode file_read_big_block(FILE *file, char *block, Ulong size) - /* Read in a big block. Could be bigger than 64K. */ -{ - char *pt = block; - unsigned size1; - - while (size != 0) - { - size1 = ((size > 0xFFF0) ? 0xFFF0 : size); - if ( fread(pt, size1, 1, file) != 1 ) - return ErrFlicRead; - pt += size1; // Advance pointer to next batch. - size -= size1; // Subtract current batch from size to go. - } - return 0; -} - -//************************************************************************** -// -// fill_in_frame2 -// -// This figures out where the second frame of the flic is -// (useful for playing in a loop). -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static ErrCode fill_in_frame2(Flic *flic) -{ - FrameHead head; - //ErrCode err; - - (*flic->seek)(flic, flic->head.oframe1); - if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) - return ErrFlicRead; - - if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) - return ErrFlicRead; - - flic->head.oframe2 = flic->head.oframe1 + head.size; - - return 0; -} - -//************************************************************************** -// -// flic_next_frame -// -// Advance to next frame of flic. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static ErrCode flic_next_frame(Flic *flic, BOOL fDecode) -{ - FrameHead head; - ErrCode err = 0; - long size; - - if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) - err = ErrFlicRead; - else - { - if (head.type == FRAME_TYPE) - { - size = head.size - sizeof(head); /* Don't include head. */ - if (size > 0) - { - if (size > 500000) - { - //TRACE("FLC chunk too big: %d\n",size); - //Assert(0); - FastDebugMsg(String("flic_next_frame: FLC chunk too big: %d", size)); - size = 64000; - } - if (!(err = file_read_big_block(flic->file, pcxbuf, size))) - { - if ( fDecode ) - err = decode_frame(flic, &head, (unsigned char *)pcxbuf); - } - } - } - else - err = ErrFlicBadFrame; - } - return err; -} - -//************************************************************************** -// -// flic_check_frame -// -// A dummy routine to be called for each frame. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static Boolean flic_check_frame(Flic *flic) -{ - return TRUE; -} - -//************************************************************************** -// -// File io -// -//************************************************************************** - -static ErrCode flic_open(Flic *flic, const char *filename) -{ - return (flic->file = fopen(filename, "rb")) ? 0 : ErrFlicAccess; -} - -static ErrCode flic_seek(Flic *flic, long offset) -{ - return fseek(flic->file, offset, SEEK_SET) ? ErrFlicSeek : 0; -} - -//************************************************************************** -// -// FlicInit -// -// Initializes a flic object. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicInit(Flic *flic, unsigned screen_width, unsigned screen_height, char change_palette, char *Buff) -{ - flic->file = NULL; - //flic->lib.names = NULL; - - flic->open = flic_open; /* Set routines for single flick file access */ - flic->seek = flic_seek; - - flic->check_frame = flic_check_frame; /* Select a dummy routine */ - - /** Info used by low level routines */ - - flic->screen.pixels = (unsigned char *)Buff; // (char *) 0xa0000; - flic->screen.width = screen_width; - flic->screen.height = screen_height; - flic->screen.change_palette = change_palette; -} - -//************************************************************************** -// -// FlicOpen -// -// Opens a flic file or locates a flic file in a library. -// -// Parameter List : -// -// Flic *flic -> the flic -// const char *filename -> filename of flic to open -// -// Return Value : -// Modification history : -// -//************************************************************************** - -ErrCode FlicOpen(Flic *flic, const char *filename) -{ - ErrCode err; - - flic->xoff = flic->yoff = 0; - - if ( !(err = (*flic->open)(flic, filename)) ) - { - if (fread(&flic->head, sizeof(flic->head), 1, flic->file) != 1) - err = ErrFlicRead; - else - { - flic->name = filename; - - if (flic->head.type == FLC_TYPE) - { - /* Seek frame 1. */ - (*flic->seek)(flic, flic->head.oframe1); - return 0; - } - if (flic->head.type == FLI_TYPE) - { - long i; - /* Do some conversion work here. */ - flic->head.oframe1 = sizeof(flic->head); - i=flic->head.speed * 1000L; - flic->head.speed = i / 70; - return 0; - } - else - { - err = ErrFlicBad; - printf("flic was bad! \n"); - _getch(); - exit(0); - } - } - } - - FlicClose(flic); /* Close down and scrub partially opened flic. */ - return err; -} - -//************************************************************************** -// -// FlicSetOrigin -// -// Sets the location of the top left corner of the flic in terms of screen -// coordinates. -// -// Parameter List : -// -// Flic *flic -> the flic -// unsigned x -> x-coord of origin -// unsigned y -> y-coord of origin -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicSetOrigin(Flic *flic, unsigned x, unsigned y) -{ - flic->xoff = x; - flic->yoff = y; -} - -//************************************************************************** -// -// FlicClose -// -// Closes a flic file if one is open. If a library is open, this function has -// no effect. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicClose(Flic *flic) -{ - if ( flic->file ) - { - fclose(flic->file); - flic->file = NULL; - } -} - -//************************************************************************** -// -// flic_play_loop_timer -// -// This routine is called at the end of each timer period. The timer is used -// by the FlicPlay routine. The global variable timer_flag indicates that -// a time interval has elapsed. FlicPlay resets timer_flag for the next -// interval. -// -// Stack checking must be disabled. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -#ifdef DEBUG -#pragma off (check_stack) -#endif - -static volatile int timer_flag=1; - -static void flic_play_loop_timer() -{ - timer_flag = 1; -} - -#ifdef DEBUG -#pragma on (check_stack) -#endif - -//************************************************************************** -// -// FlicPlay -// -// This is the engine for the flic display system. Call this function to -// display a flic. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -ErrCode FlicPlay(Flic *flic, Ulong max_loop) -{ -/* - ErrCode err; - HTIMER timer; - - flic->status.max_loop_count = max_loop; - flic->status.max_frame_index = flic->head.frames; - - if (flic->head.oframe2 == 0) - { - fill_in_frame2(flic); - // FastBlitRegionSVGA((char *)(0xa0000),(char *)(flic->screen.pixels),(long)0,(long)640,(long)480,(long)0,(long)640); - // BlitSVGAPage((char *)(flic->screen.pixels)); - // BlitRegionSVGATst((void *)0xa0000,(void *)(flic->screen.pixels),(long)640,(long)480,(long)640); - //BlitRegionSVGA((char *)0xa0000,(char *)flic->screen.pixels,(long)0,(long)640,(long)480,(long)0,(long)640); - } - - // Seek to first frame. - (*flic->seek)(flic, flic->head.oframe1); - // Save time to move on. - - //videoSetMode(3); - //printf("speed is %d\n",flic->head.speed); - //_getch(); - //exit(0); - - //timer = AIL_register_timer(flic_play_loop_timer); - //AIL_set_timer_period(timer, flic->head.speed* 1000); - //timer_flag = 0; - //AIL_start_timer(timer); - - // Display first frame. - if (err = flic_next_frame(flic, TRUE)) - { - //AIL_release_timer_handle(timer); - return err; - } - - for (flic->status.loop_count = 0; !max_loop || flic->status.loop_count < max_loop; - ++flic->status.loop_count) - { - // Seek to second frame - (*flic->seek)(flic, flic->head.oframe2); - // Loop from 2nd frame thru ring frame - for (flic->status.frame_index=0; - (flic->status.frame_index < (flic->head.frames-1)) || - ( (flic->status.frame_index < flic->head.frames) && - ( !max_loop || (flic->status.loop_count < (max_loop - 1)))); - ++flic->status.frame_index) - { - while (!timer_flag); - - if (err = flic_next_frame(flic, TRUE)) - return err; - //else - // FastBlitRegionSVGA((char *)(0xa0000),(char *)(flic->screen.pixels),(long)0,(long)640,(long)480,(long)0,(long)640); - // BlitSVGAPage((char *)(flic->screen.pixels)); - // BlitRegionSVGATst((void *)0xa0000,(void *)(flic->screen.pixels),(long)640,(long)480,(long)640); - // BlitRegionSVGA((char *)0xa0000,(char *)flic->screen.pixels,(long)0,(long)640,(long)480,(long)0,(long)640); - - timer_flag = 0; - } - } - - //AIL_release_timer_handle(timer); -*/ - return 0; -} - -void FlicSeekFirst(Flic *flic) -{ -// if (flic->head.oframe2 == 0) -// fill_in_frame2(flic); - - // Seek to first frame. - flic_seek(flic, flic->head.oframe1); - - // Display first frame. - //flic_next_frame(flic, TRUE); HJH - flic->status.frame_index=0;//1; HJH -} - -int FlicAdvance(Flic *flic, BOOL fDecode) -{ - // Seek to second frame - //(*flic->seek)(flic, flic->head.oframe2); - // Loop from 2nd frame thru ring frame - - // for (flic->status.frame_index=0; - // (flic->status.frame_index < (flic->head.frames-1)) || - // ( (flic->status.frame_index < flic->head.frames) && - // ( !max_loop || (flic->status.loop_count < (max_loop - 1)))); - // ++flic->status.frame_index) - // { - - if(flic->status.frame_index < flic->head.frames) - { - flic_next_frame(flic, fDecode); - flic->status.frame_index++; - //memcpy(buffer, buffer2, (HSIZE*VSIZE)); - return(1); - } - else - return(0); - - // if (flic->check_frame && !(*flic->check_frame)(flic)) - // return 0; -} - -static void center_flic(Flic *flic) - /* Set flic.xoff and flic.yoff so flic plays centered rather - * than in upper left corner of display. */ -{ - flic->xoff = (flic->screen.width - (signed)flic->head.width)/2; - flic->yoff = (flic->screen.height - (signed)flic->head.height)/2; -} - -void set_flic_origin(Flic *flic, int x, int y) -{ - flic->xoff = x; - flic->yoff = y; -} - -int frame_check(Flic *flic) -{ -/* - char key; - - if (Esc()) - { - //AbortScript = TRUE; - return 0; - } - - if (flic->status.frame_index == FlcSoundFrames[FlcSoundIndex][0]) - { - // if the "sound" number is less than 100, then it's a VOC buffer - if (FlcSoundFrames[FlcSoundIndex][1] < 100) - { - PlayVoc(FlcSoundFrames[FlcSoundIndex][1],-1); - } - else // otherwise a raw sound data file to be streamed off of disk - { - if (FlcSoundNameList[FlcSoundNameIndex][0]!='\0') - { - retcode = lmLibSeek(SNDLIBINFO,FlcSoundNameList[FlcSoundNameIndex++],&SNDoffset,&SNDlength); - if (retcode == 0) - StPlay(glbPlayRate,IGNORE_AUDIO_GAPS); - } - } - - // now that the sound has been triggered, ready the next frame number - FlcSoundIndex++; - } - else - if (FlcSoundFrames[FlcSoundIndex][0] == 9998) // start music? - { - PlayXmi(FlcSoundFrames[FlcSoundIndex++][1],FALSE); - XmiVolume(1,127,0); - } - RefreshSound(); -*/ - return 1; -} - -//************************************************************************** -// -// FlicStart -// -// Parameter List : -// -// char *filename -> filename of flic to start processing -// char *buffer -> screen buffer to put data into -// Flic *flic -> the flic -// int usepal -> flag - should we use the palette? (I think) -// -// Return Value : -// Modification history : -// -//************************************************************************** - -int FlicStart(char *filename, int width, int height, char *buffer, Flic *flic, char usepal) -{ - FlicInit(flic, width, height, usepal, buffer); - - if(FlicOpen(flic, filename)) - return(-1); - - FlicSetOrigin(flic, 0, 0); - FlicSeekFirst(flic); - FlicAdvance(flic, TRUE); // HJH - we go to 1st, then go process it - - //memcpy(buffer, buffer2, (HSIZE*VSIZE)); - - return(0); -} - -//************************************************************************** -// -// FlicStop -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicStop(Flic *flic) -{ - FlicClose(flic); -} - -//************************************************************************** -// -// FlicGetStats -// -// Gets statistics for the given file. -// -// Parameter List : -// -// char *filename -> the flic filename -// Flic *flic -> the flic -// int *piBufferSize -> this function will fill in how large a -// buffer is needed to store a screen of -// this flick -// int *piColourPalSize->this function will fill in how large -// the colour palette is -// -// Return Value : -// -// ErrCode -> 0 if successfull, non-zero otherwise -// -// Modification history : -// -// 05jun96:HJH -> creation -// -//************************************************************************** - -ErrCode FlicGetStats(char *filename, int width, int height, Flic *flic, int *piBufferSize, int *piColourPalSize) -{ - ErrCode err=0; - FlicInit(flic, width, height, 1, NULL); - - flic->xoff = flic->yoff = 0; - - if ( !(err = (*flic->open)(flic, filename)) ) - { - if (fread(&flic->head, sizeof(flic->head), 1, flic->file) != 1) - err = ErrFlicRead; - } - - if ( !err && piBufferSize ) - *piBufferSize = flic->head.width * flic->head.height; - - FlicSeekChunk( flic, 0, COLOR_256, piColourPalSize ); - FlicClose(flic); /* Close down and scrub partially opened flic. */ - - return err; -} - -//************************************************************************** -// -// FlicGetColourPalette -// -// To get the colour palette from the given flic file. -// -// Parameter List : -// -// char *filename -> the flic file to extract the palette from -// char **ppBuffer -> the place to put the palette -// -// Return Value : -// -// ErrCode -> 0 if successful, non-zero otherwise -// -// Modification history : -// -// 10jun96:HJH -> creation -// 19jun96:HJH -> removed <<2 after colors->r/g/b -// -//************************************************************************** - -ErrCode FlicGetColourPalette(CHAR *filename, int width, int height, CHAR **ppBuffer, INT *piNumColours) -{ - Flic flic; - INT iBufferSize; - INT iColourPaletteSize=0; - ErrCode err = 0; - ChunkHead *chunk = NULL; - CHAR *pcPosition; - - if ( FlicGetStats( filename, width, height, &flic, &iBufferSize, &iColourPaletteSize ) ) - err = -1; - - if ( piNumColours ) - *piNumColours = iColourPaletteSize; - - if ( !err && iColourPaletteSize ) - { - FlicInit(&flic, flic.head.width, flic.head.height, 1, NULL); - - if(FlicOpen(&flic, filename)) - return(-1); - - FlicSetOrigin(&flic, 0, 0); - - *ppBuffer = (CHAR *)MemAlloc( iColourPaletteSize ); - chunk = (ChunkHead *)FlicSeekChunk( &flic, 0, COLOR_256, NULL ); - pcPosition = (CHAR *)(((BYTE *)chunk)+6); - - if ( chunk ) - { - INT ix, end, count, start = 0; - Uchar *cbuf = (Uchar *)pcPosition; - Short *wp = (Short *)cbuf; - Short ops; - Colour *colors; - - ops = *wp; - cbuf += sizeof(*wp); - while (--ops >= 0) - { - start += *cbuf++; - if ((count = *cbuf++) == 0) - count = 256; - { - colors = (Colour *)cbuf; - end = start + count; - - for (ix = start; ix < end; ++ix) - { - (*ppBuffer)[ix*3] =colors->r; - (*ppBuffer)[ix*3+1]=colors->g; - (*ppBuffer)[ix*3+2]=colors->b; - ++colors; - } - } - cbuf += 3*count; - start += count; - } - } - } - else - { - err = -1; - } - - return(err); -} - -//************************************************************************** -// -// FlicSeekChunk -// -// To seek to a particular chunk in the flic file. -// -// Parameter List : -// -// Flic *flic -> the flic to search -// INT iFrame -> frame in which to search -// ChunkTypes eType -> type of chunk to search for -// INT *piChunkSize-> the function puts the size of the chunk here -// -// Return Value : -// -// char * -> the returned chunk -// -// Modification history : -// -// 05jun96:HJH -> creation -// -//************************************************************************** - -CHAR *FlicSeekChunk(Flic *flic, INT iFrame, ChunkTypes eType, INT *piChunkSize) -{ - FrameHead head; - LONG lSize; - ErrCode err=0; - INT i; - - FlicSeekFirst(flic); - - for ( i=0 ; i