diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d05169d9..c25feead 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -154,7 +154,7 @@ jobs: cat dist/versions.env - name: Upload - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: versions.env path: dist/ @@ -179,77 +179,41 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: - path: artifacts + path: dist + pattern: '*_release' + merge-multiple: true - - name: Move release archives to dist/ - shell: bash - run: | - set -eux - mkdir dist/ - mv artifacts/*_release/* dist/ - - - name: Delete Latest Release and Tag - if: github.ref == 'refs/heads/master' - uses: dev-drprasad/delete-tag-and-release@v1.0 - with: - delete_release: true - tag_name: "latest" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Checkout Repo if: github.ref == 'refs/heads/master' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: source fetch-depth: 1 sparse-checkout: 'README.md' - - name: Create Latest Tag + - name: Create latest pre-release if: github.ref == 'refs/heads/master' working-directory: source run: | + gh release delete latest --cleanup-tag || true git tag -d latest || true + git push --delete origin refs/tags/latest || true git tag latest - git push origin latest - - id: release_latest - name: Release Latest - if: github.ref == 'refs/heads/master' - uses: ncipollo/release-action@v1 - with: - artifactErrorsFailBuild: true - artifacts: dist/* - generateReleaseNotes: true - makeLatest: true - name: "Latest (unstable)" - prerelease: true - tag: "latest" + git push --force origin refs/tags/latest + gh release create latest ../dist/* \ + --generate-notes \ + --title "Latest (unstable)" \ + --verify-tag \ + --prerelease + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - id: release_tag - name: Release Tag - uses: ncipollo/release-action@v1 + - name: Upload to tagged release if: startsWith(github.ref, 'refs/tags/v') - with: - allowUpdates: true - artifactErrorsFailBuild: true - artifacts: dist/* - draft: false - generateReleaseNotes: true - makeLatest: true - omitBodyDuringUpdate: true - omitDraftDuringUpdate: true - omitNameDuringUpdate: true - omitPrereleaseDuringUpdate: true - - - name: Show release outputs - shell: bash + working-directory: source run: | - echo 'id: ' - echo -n '${{ steps.release_tag.outputs.id }}' - echo -n '${{ steps.release_latest.outputs.id }}' - echo '' - echo '' - echo 'url:' - echo -n '${{ steps.release_tag.outputs.html_url }}' - echo -n '${{ steps.release_latest.outputs.html_url }}' - echo '' + exit 0 + gh release upload "$GITHUB_REF_NAME" ../dist/* --clobber + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build_language.yml b/.github/workflows/build_language.yml index bea5a00a..1b7d6ee4 100644 --- a/.github/workflows/build_language.yml +++ b/.github/workflows/build_language.yml @@ -30,10 +30,10 @@ jobs: steps: - name: Checkout source - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download versions.env - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: versions.env path: artifacts @@ -41,6 +41,7 @@ jobs: shell: bash run: cat artifacts/versions.env >> $GITHUB_ENV + # TODO: Move this into CMake, just taking the GitHub Actions parameters as -D variables - name: Update GameVersion.cpp shell: bash run: | @@ -49,9 +50,9 @@ jobs: GAME_VERSION=$(echo "$GAME_VERSION" | tr -cd '[:print:]' | tr -d '"\\') GAME_BUILD="${INPUTS_LANGUAGE:0:2} $GAME_BUILD_INFORMATION" GAME_BUILD=$(echo "$GAME_BUILD" | tr -cd '[:print:]' | tr -d '"\\') - sed -i "s|@Version@|${GAME_VERSION:0:15}|" GameVersion.cpp - sed -i "s|@Build@|${GAME_BUILD:0:255}|" GameVersion.cpp - cat GameVersion.cpp + sed -i "s|@Version@|${GAME_VERSION:0:15}|" Ja2/GameVersion.cpp + sed -i "s|@Build@|${GAME_BUILD:0:255}|" Ja2/GameVersion.cpp + cat Ja2/GameVersion.cpp - name: Prepare build properties shell: bash @@ -68,7 +69,7 @@ jobs: JA2Application=$JA2Application " >> $GITHUB_ENV - - uses: microsoft/setup-msbuild@v1.1 + - uses: microsoft/setup-msbuild@v2 with: msbuild-architecture: x86 - uses: ilammy/msvc-dev-cmd@v1 @@ -86,7 +87,7 @@ jobs: find build/ - name: Upload - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ inputs.language }}_${{ matrix.application }} path: build/*.exe @@ -99,7 +100,7 @@ jobs: steps: - name: Download versions.env - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: versions.env path: artifacts @@ -108,7 +109,7 @@ jobs: run: cat artifacts/versions.env >> $GITHUB_ENV - name: Checkout gamedir - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ env.GAMEDIR_REPOSITORY }} ref: ${{ env.GAMEDIR_COMMIT_SHA }} @@ -116,7 +117,7 @@ jobs: - name: Checkout gamedir-languages if: inputs.language != 'English' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ env.GAMEDIR_LANGUAGES_REPOSITORY }} ref: ${{ env.GAMEDIR_LANGUAGES_COMMIT_SHA }} @@ -130,25 +131,25 @@ jobs: cp -a gamedir-languages/${{ inputs.language }}_Version/* gamedir/ - name: Download ja2 - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ inputs.language }}_ja2 path: artifacts/ja2 - name: Download ja2mapeditor - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ inputs.language }}_ja2mapeditor path: artifacts/ja2mapeditor - name: Download ja2ub - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ inputs.language }}_ja2ub path: artifacts/ja2ub - name: Download ja2ubmapeditor - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ inputs.language }}_ja2ubmapeditor path: artifacts/ja2ubmapeditor @@ -198,7 +199,8 @@ jobs: 7z a -bb -xr'!.*' "../dist/${DIST_NAME}.7z" . - name: Upload - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ inputs.language }}_release path: dist/ + compression-level: 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a36e848..e70ac481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(usingMsBuild $) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP _CRT_SECURE_NO_DEPRECATE) -include_directories(${CMAKE_SOURCE_DIR} "ext/VFS/include" Utils TileEngine TacticalAI ModularizedTacticalAI Tactical Strategic "Standard Gaming Platform" Res Lua Laptop Multiplayer "Multiplayer/raknet" Editor Console) +include_directories(Ja2 "ext/VFS/include" Utils TileEngine TacticalAI "ModularizedTacticalAI/include" Tactical Strategic sgp "Ja2/Res" Lua Laptop Multiplayer Editor Console) # external libraries add_subdirectory("ext/libpng") @@ -38,90 +38,28 @@ add_subdirectory("ext/export/src") # by header files do not rely on Applications or Languages preprocessor definitions, # and therefore only need to be compiled once. Good. add_subdirectory(Lua) +add_subdirectory(Multiplayer) # static libraries whose source files, header files or header files included # by header files rely on Application and Language preprocessor definitions, and # therefore need to be compiled multiple times. Very Bad. -add_subdirectory(TileEngine) -add_subdirectory(TacticalAI) -add_subdirectory(Utils) -add_subdirectory(Strategic) -add_subdirectory("Standard Gaming Platform") -add_subdirectory(Laptop) -add_subdirectory(Editor) -add_subdirectory(Console) -add_subdirectory(Tactical) -add_subdirectory(ModularizedTacticalAI) -# TODO: Rename 'Standard Gaming Platform' directory to 'SGP' so this can be refactored away set(Ja2_Libs TileEngine TacticalAI Utils Strategic -SGP +sgp Laptop Editor Console Tactical ModularizedTacticalAI ) +foreach(lib IN LISTS Ja2_Libs) + add_subdirectory(${lib}) +endforeach() -# TODO: Move these units into their own directory to declutter the root dir and CMakeLists.txt file -set(Ja2Src -"aniviewscreen.cpp" -"Credits.cpp" -"Fade Screen.cpp" -"FeaturesScreen.cpp" -"GameInitOptionsScreen.cpp" -"gameloop.cpp" -"gamescreen.cpp" -"GameSettings.cpp" -"GameVersion.cpp" -"HelpScreen.cpp" -"Init.cpp" -"Intro.cpp" -"JA2 Splash.cpp" -"Ja25Update.cpp" -"jascreens.cpp" -"Language Defines.cpp" -"Loading Screen.cpp" -"MainMenuScreen.cpp" -"MessageBoxScreen.cpp" -"MPChatScreen.cpp" -"MPConnectScreen.cpp" -"MPHostScreen.cpp" -"MPJoinScreen.cpp" -"MPScoreScreen.cpp" -"MPXmlTeams.cpp" -"Multiplayer/client.cpp" -"Multiplayer/server.cpp" -"Multiplayer/transfer_rules.cpp" -"Options Screen.cpp" -"profiler.cpp" -"SaveLoadGame.cpp" -"SaveLoadScreen.cpp" -"SCREENS.cpp" -"Sys Globals.cpp" -"ub_config.cpp" -"XML_DifficultySettings.cpp" -"XML_IntroFiles.cpp" -"XML_Layout_MainMenu.cpp" -Res/ja2.rc -) - -set(Ja2_Libraries -"${PROJECT_SOURCE_DIR}/libexpatMT.lib" -"Dbghelp.lib" -Lua -"${PROJECT_SOURCE_DIR}/lua51.lib" -"${PROJECT_SOURCE_DIR}/lua51.vc9.lib" -"Winmm.lib" -"${PROJECT_SOURCE_DIR}/SMACKW32.LIB" -"${PROJECT_SOURCE_DIR}/binkw32.lib" -bfVFS -"${PROJECT_SOURCE_DIR}/Multiplayer/raknet/RakNetLibStatic.lib" -"ws2_32.lib" -) +add_subdirectory(Ja2) # simple function to validate Languages and Application choices include(cmake/ValidateOptions.cmake) @@ -160,7 +98,7 @@ foreach(lang IN LISTS LangTargets) set(isUb $) set(isUbEditor $) - # static library for an app/lang combination, e.g. JA2_ENGLISH_SGP.lib + # static library for an app/lang combination, e.g. JA2_ENGLISH_sgp.lib add_library(${VeryBadLib}) target_sources(${VeryBadLib} PRIVATE ${${lib}Src}) @@ -174,9 +112,9 @@ foreach(lang IN LISTS LangTargets) target_link_libraries(${Executable} PUBLIC ${VeryBadLib}) endforeach() - # for SGP only - target_link_libraries(${Executable}_SGP PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") - target_link_libraries(${Executable}_SGP PUBLIC libpng) - target_compile_definitions(${Executable}_SGP PRIVATE NO_ZLIB_COMPRESSION) + # for sgp only + target_link_libraries(${Executable}_sgp PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") + target_link_libraries(${Executable}_sgp PUBLIC libpng) + target_compile_definitions(${Executable}_sgp PRIVATE NO_ZLIB_COMPRESSION) endforeach() endforeach() diff --git a/Editor/editscreen.cpp b/Editor/editscreen.cpp index a62be1e5..1cd2ceb3 100644 --- a/Editor/editscreen.cpp +++ b/Editor/editscreen.cpp @@ -79,8 +79,6 @@ class OBJECTTYPE; class SOLDIERTYPE; -extern CHAR8 *szMusicList[NUM_MUSIC]; - BOOLEAN gfCorruptMap = FALSE; BOOLEAN gfCorruptSchedules = FALSE; BOOLEAN gfProfileDataLoaded = FALSE; @@ -169,6 +167,7 @@ LEVELNODE *gCursorNode = NULL; INT32 gsCursorGridNo; INT32 giMusicID = 0; +NewMusicList gMusicMode = MUSICLIST_MAIN_MENU; void EraseWorldData( ); @@ -1616,16 +1615,27 @@ void HandleKeyboardShortcuts( ) break; case F4: -#ifdef NEWMUSIC - MusicPlay( giMusicID, MUSIC_OLD_TYPE, FALSE ); -#else - MusicPlay( giMusicID ); -#endif + MusicPlay(gMusicMode, giMusicID); + ScreenMsg( FONT_YELLOW, MSG_INTERFACE, L"%S", MusicLists[gMusicMode][giMusicID] ); - ScreenMsg( FONT_YELLOW, MSG_DEBUG, L"%S", szMusicList[giMusicID] ); + // Select next track giMusicID++; - if( giMusicID >= NUM_MUSIC ) + if (giMusicID >= MusicLists[gMusicMode].size()) + { giMusicID = 0; + for (size_t i = 0; i < MAX_MUSIC; i++) + { + if (gMusicMode == i) + { + gMusicMode = static_cast(i + 1); + if (gMusicMode == MAX_MUSIC) + { + gMusicMode = MUSICLIST_MAIN_MENU; + } + break; + } + } + } break; case F5: diff --git a/JA2 Demo Ads.h b/JA2 Demo Ads.h deleted file mode 100644 index 2d5d97c7..00000000 --- a/JA2 Demo Ads.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _JA2_DEMO_ADS_H -#define _JA2_DEMO_ADS_H - -#include "types.h" - -#endif \ No newline at end of file diff --git a/JA2Prototypes.h b/JA2Prototypes.h deleted file mode 100644 index bb7e6d8c..00000000 --- a/JA2Prototypes.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _JA2PROTOTYPES_H -#define _JA2PROTOTYPES_H - -/* - * This header does not define any structures. It simply provides a way for all code that only needs a pointer - * reference to structures, to have it without getting locked into mutual includes and other - * hard-to-trace-and-fix behavior. More class and struct defs can be added as necessary. - */ - -class SOLDIERTYPE; -struct AnimationSurfaceType; - -#endif diff --git a/Ja2/CMakeLists.txt b/Ja2/CMakeLists.txt new file mode 100644 index 00000000..aeafd680 --- /dev/null +++ b/Ja2/CMakeLists.txt @@ -0,0 +1,52 @@ +set(Ja2Src +"${CMAKE_CURRENT_SOURCE_DIR}/aniviewscreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Credits.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Fade Screen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/FeaturesScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/GameInitOptionsScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/gameloop.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/gamescreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/GameSettings.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/GameVersion.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/HelpScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Init.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Intro.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/JA2 Splash.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Ja25Update.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/jascreens.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Language Defines.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Loading Screen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MainMenuScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MessageBoxScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPChatScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPConnectScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPHostScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPJoinScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPScoreScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPXmlTeams.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Options Screen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/profiler.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/SaveLoadGame.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/SaveLoadScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/SCREENS.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Sys Globals.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/ub_config.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/XML_DifficultySettings.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/XML_IntroFiles.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/XML_Layout_MainMenu.cpp" +${CMAKE_CURRENT_SOURCE_DIR}/Res/ja2.rc +PARENT_SCOPE) + +set(Ja2_Libraries +"${CMAKE_SOURCE_DIR}/libexpatMT.lib" +"Dbghelp.lib" +Lua +"${CMAKE_SOURCE_DIR}/lua51.lib" +"${CMAKE_SOURCE_DIR}/lua51.vc9.lib" +"Winmm.lib" +"${CMAKE_SOURCE_DIR}/SMACKW32.LIB" +"${CMAKE_SOURCE_DIR}/binkw32.lib" +bfVFS +"ws2_32.lib" +Multiplayer +PARENT_SCOPE) diff --git a/Cheats.h b/Ja2/Cheats.h similarity index 100% rename from Cheats.h rename to Ja2/Cheats.h diff --git a/Credits.cpp b/Ja2/Credits.cpp similarity index 100% rename from Credits.cpp rename to Ja2/Credits.cpp diff --git a/Credits.h b/Ja2/Credits.h similarity index 100% rename from Credits.h rename to Ja2/Credits.h diff --git a/Fade Screen.cpp b/Ja2/Fade Screen.cpp similarity index 100% rename from Fade Screen.cpp rename to Ja2/Fade Screen.cpp diff --git a/Fade Screen.h b/Ja2/Fade Screen.h similarity index 100% rename from Fade Screen.h rename to Ja2/Fade Screen.h diff --git a/FeaturesScreen.cpp b/Ja2/FeaturesScreen.cpp similarity index 100% rename from FeaturesScreen.cpp rename to Ja2/FeaturesScreen.cpp diff --git a/FeaturesScreen.h b/Ja2/FeaturesScreen.h similarity index 100% rename from FeaturesScreen.h rename to Ja2/FeaturesScreen.h diff --git a/GameInitOptionsScreen.cpp b/Ja2/GameInitOptionsScreen.cpp similarity index 100% rename from GameInitOptionsScreen.cpp rename to Ja2/GameInitOptionsScreen.cpp diff --git a/GameInitOptionsScreen.h b/Ja2/GameInitOptionsScreen.h similarity index 100% rename from GameInitOptionsScreen.h rename to Ja2/GameInitOptionsScreen.h diff --git a/GameSettings.cpp b/Ja2/GameSettings.cpp similarity index 100% rename from GameSettings.cpp rename to Ja2/GameSettings.cpp diff --git a/GameSettings.h b/Ja2/GameSettings.h similarity index 100% rename from GameSettings.h rename to Ja2/GameSettings.h diff --git a/GameVersion.cpp b/Ja2/GameVersion.cpp similarity index 100% rename from GameVersion.cpp rename to Ja2/GameVersion.cpp diff --git a/GameVersion.h b/Ja2/GameVersion.h similarity index 100% rename from GameVersion.h rename to Ja2/GameVersion.h diff --git a/HelpScreen.cpp b/Ja2/HelpScreen.cpp similarity index 100% rename from HelpScreen.cpp rename to Ja2/HelpScreen.cpp diff --git a/HelpScreen.h b/Ja2/HelpScreen.h similarity index 100% rename from HelpScreen.h rename to Ja2/HelpScreen.h diff --git a/HelpScreenText.h b/Ja2/HelpScreenText.h similarity index 100% rename from HelpScreenText.h rename to Ja2/HelpScreenText.h diff --git a/Init.cpp b/Ja2/Init.cpp similarity index 100% rename from Init.cpp rename to Ja2/Init.cpp diff --git a/Init.h b/Ja2/Init.h similarity index 100% rename from Init.h rename to Ja2/Init.h diff --git a/Intro.cpp b/Ja2/Intro.cpp similarity index 100% rename from Intro.cpp rename to Ja2/Intro.cpp diff --git a/Intro.h b/Ja2/Intro.h similarity index 100% rename from Intro.h rename to Ja2/Intro.h diff --git a/JA2 Splash.cpp b/Ja2/JA2 Splash.cpp similarity index 100% rename from JA2 Splash.cpp rename to Ja2/JA2 Splash.cpp diff --git a/JA2 Splash.h b/Ja2/JA2 Splash.h similarity index 100% rename from JA2 Splash.h rename to Ja2/JA2 Splash.h diff --git a/Ja25Update.cpp b/Ja2/Ja25Update.cpp similarity index 94% rename from Ja25Update.cpp rename to Ja2/Ja25Update.cpp index 101b1152..4fd737e1 100644 --- a/Ja25Update.cpp +++ b/Ja2/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/Ja25Update.h b/Ja2/Ja25Update.h similarity index 100% rename from Ja25Update.h rename to Ja2/Ja25Update.h diff --git a/Language Defines.cpp b/Ja2/Language Defines.cpp similarity index 100% rename from Language Defines.cpp rename to Ja2/Language Defines.cpp diff --git a/Language Defines.h b/Ja2/Language Defines.h similarity index 100% rename from Language Defines.h rename to Ja2/Language Defines.h diff --git a/Loading Screen.cpp b/Ja2/Loading Screen.cpp similarity index 100% rename from Loading Screen.cpp rename to Ja2/Loading Screen.cpp diff --git a/Loading Screen.h b/Ja2/Loading Screen.h similarity index 100% rename from Loading Screen.h rename to Ja2/Loading Screen.h diff --git a/MPChatScreen.cpp b/Ja2/MPChatScreen.cpp similarity index 100% rename from MPChatScreen.cpp rename to Ja2/MPChatScreen.cpp diff --git a/MPChatScreen.h b/Ja2/MPChatScreen.h similarity index 100% rename from MPChatScreen.h rename to Ja2/MPChatScreen.h diff --git a/MPConnectScreen.cpp b/Ja2/MPConnectScreen.cpp similarity index 100% rename from MPConnectScreen.cpp rename to Ja2/MPConnectScreen.cpp diff --git a/MPConnectScreen.h b/Ja2/MPConnectScreen.h similarity index 100% rename from MPConnectScreen.h rename to Ja2/MPConnectScreen.h diff --git a/MPHostScreen.cpp b/Ja2/MPHostScreen.cpp similarity index 100% rename from MPHostScreen.cpp rename to Ja2/MPHostScreen.cpp diff --git a/MPHostScreen.h b/Ja2/MPHostScreen.h similarity index 100% rename from MPHostScreen.h rename to Ja2/MPHostScreen.h diff --git a/MPJoinScreen.cpp b/Ja2/MPJoinScreen.cpp similarity index 100% rename from MPJoinScreen.cpp rename to Ja2/MPJoinScreen.cpp diff --git a/MPJoinScreen.h b/Ja2/MPJoinScreen.h similarity index 100% rename from MPJoinScreen.h rename to Ja2/MPJoinScreen.h diff --git a/MPScoreScreen.cpp b/Ja2/MPScoreScreen.cpp similarity index 100% rename from MPScoreScreen.cpp rename to Ja2/MPScoreScreen.cpp diff --git a/MPScoreScreen.h b/Ja2/MPScoreScreen.h similarity index 100% rename from MPScoreScreen.h rename to Ja2/MPScoreScreen.h diff --git a/MPXmlTeams.cpp b/Ja2/MPXmlTeams.cpp similarity index 100% rename from MPXmlTeams.cpp rename to Ja2/MPXmlTeams.cpp diff --git a/MPXmlTeams.hpp b/Ja2/MPXmlTeams.hpp similarity index 100% rename from MPXmlTeams.hpp rename to Ja2/MPXmlTeams.hpp diff --git a/MainMenuScreen.cpp b/Ja2/MainMenuScreen.cpp similarity index 100% rename from MainMenuScreen.cpp rename to Ja2/MainMenuScreen.cpp diff --git a/MessageBoxScreen.cpp b/Ja2/MessageBoxScreen.cpp similarity index 100% rename from MessageBoxScreen.cpp rename to Ja2/MessageBoxScreen.cpp diff --git a/MessageBoxScreen.h b/Ja2/MessageBoxScreen.h similarity index 100% rename from MessageBoxScreen.h rename to Ja2/MessageBoxScreen.h diff --git a/Options Screen.cpp b/Ja2/Options Screen.cpp similarity index 100% rename from Options Screen.cpp rename to Ja2/Options Screen.cpp diff --git a/Options Screen.h b/Ja2/Options Screen.h similarity index 100% rename from Options Screen.h rename to Ja2/Options Screen.h diff --git a/Res/ja2.aps b/Ja2/Res/ja2.aps similarity index 100% rename from Res/ja2.aps rename to Ja2/Res/ja2.aps diff --git a/Res/ja2.rc b/Ja2/Res/ja2.rc similarity index 100% rename from Res/ja2.rc rename to Ja2/Res/ja2.rc diff --git a/Res/jagged3.ico b/Ja2/Res/jagged3.ico similarity index 100% rename from Res/jagged3.ico rename to Ja2/Res/jagged3.ico diff --git a/Res/resource.h b/Ja2/Res/resource.h similarity index 100% rename from Res/resource.h rename to Ja2/Res/resource.h diff --git a/SaveLoadGame.cpp b/Ja2/SaveLoadGame.cpp similarity index 96% rename from SaveLoadGame.cpp rename to Ja2/SaveLoadGame.cpp index a013b455..7d8cc015 100644 --- a/SaveLoadGame.cpp +++ b/Ja2/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 ) @@ -9961,69 +9946,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/Ja2/SaveLoadGame.h similarity index 94% rename from SaveLoadGame.h rename to Ja2/SaveLoadGame.h index a1f9664a..3cc011f6 100644 --- a/SaveLoadGame.h +++ b/Ja2/SaveLoadGame.h @@ -93,13 +93,10 @@ 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 ); 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/SaveLoadScreen.cpp b/Ja2/SaveLoadScreen.cpp similarity index 100% rename from SaveLoadScreen.cpp rename to Ja2/SaveLoadScreen.cpp diff --git a/SaveLoadScreen.h b/Ja2/SaveLoadScreen.h similarity index 100% rename from SaveLoadScreen.h rename to Ja2/SaveLoadScreen.h diff --git a/Screens.cpp b/Ja2/Screens.cpp similarity index 100% rename from Screens.cpp rename to Ja2/Screens.cpp diff --git a/Screens.h b/Ja2/Screens.h similarity index 100% rename from Screens.h rename to Ja2/Screens.h diff --git a/Sys Globals.cpp b/Ja2/Sys Globals.cpp similarity index 100% rename from Sys Globals.cpp rename to Ja2/Sys Globals.cpp diff --git a/Sys Globals.h b/Ja2/Sys Globals.h similarity index 100% rename from Sys Globals.h rename to Ja2/Sys Globals.h diff --git a/VtuneApi.h b/Ja2/VtuneApi.h similarity index 100% rename from VtuneApi.h rename to Ja2/VtuneApi.h diff --git a/XML_DifficultySettings.cpp b/Ja2/XML_DifficultySettings.cpp similarity index 100% rename from XML_DifficultySettings.cpp rename to Ja2/XML_DifficultySettings.cpp diff --git a/XML_IntroFiles.cpp b/Ja2/XML_IntroFiles.cpp similarity index 100% rename from XML_IntroFiles.cpp rename to Ja2/XML_IntroFiles.cpp diff --git a/XML_Layout_MainMenu.cpp b/Ja2/XML_Layout_MainMenu.cpp similarity index 100% rename from XML_Layout_MainMenu.cpp rename to Ja2/XML_Layout_MainMenu.cpp diff --git a/aniviewscreen.cpp b/Ja2/aniviewscreen.cpp similarity index 95% rename from aniviewscreen.cpp rename to Ja2/aniviewscreen.cpp index 8f05104d..638e67a2 100644 --- a/aniviewscreen.cpp +++ b/Ja2/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" diff --git a/builddefines.h b/Ja2/builddefines.h similarity index 100% rename from builddefines.h rename to Ja2/builddefines.h diff --git a/gameloop.cpp b/Ja2/gameloop.cpp similarity index 100% rename from gameloop.cpp rename to Ja2/gameloop.cpp diff --git a/gameloop.h b/Ja2/gameloop.h similarity index 100% rename from gameloop.h rename to Ja2/gameloop.h diff --git a/gamescreen.cpp b/Ja2/gamescreen.cpp similarity index 95% rename from gamescreen.cpp rename to Ja2/gamescreen.cpp index 28fd812d..ba3ceb80 100644 --- a/gamescreen.cpp +++ b/Ja2/gamescreen.cpp @@ -628,7 +628,14 @@ UINT32 MainGameScreenHandle(void) InternalLocateGridNo( gGameUBOptions.LOCATEGRIDNO, TRUE ); } #else + if (gfFirstHeliRun) + { InternalLocateGridNo( gGameExternalOptions.iInitialMercArrivalLocation, TRUE ); + } + else + { + InternalLocateGridNo(gMapInformation.sCenterGridNo, TRUE); + } #endif // Flugente: we might have reloaded the game, so we are currently not dropping mercs out of a helicopter gfIngagedInDrop = FALSE; diff --git a/gamescreen.h b/Ja2/gamescreen.h similarity index 100% rename from gamescreen.h rename to Ja2/gamescreen.h diff --git a/ja2.h b/Ja2/ja2.h similarity index 100% rename from ja2.h rename to Ja2/ja2.h diff --git a/jascreens.cpp b/Ja2/jascreens.cpp similarity index 100% rename from jascreens.cpp rename to Ja2/jascreens.cpp diff --git a/jascreens.h b/Ja2/jascreens.h similarity index 100% rename from jascreens.h rename to Ja2/jascreens.h diff --git a/legion cfg.cpp b/Ja2/legion cfg.cpp similarity index 100% rename from legion cfg.cpp rename to Ja2/legion cfg.cpp diff --git a/legion cfg.h b/Ja2/legion cfg.h similarity index 100% rename from legion cfg.h rename to Ja2/legion cfg.h diff --git a/local.h b/Ja2/local.h similarity index 100% rename from local.h rename to Ja2/local.h diff --git a/mainmenuscreen.h b/Ja2/mainmenuscreen.h similarity index 100% rename from mainmenuscreen.h rename to Ja2/mainmenuscreen.h diff --git a/profiler.cpp b/Ja2/profiler.cpp similarity index 100% rename from profiler.cpp rename to Ja2/profiler.cpp diff --git a/profiler.h b/Ja2/profiler.h similarity index 100% rename from profiler.h rename to Ja2/profiler.h diff --git a/screenids.h b/Ja2/screenids.h similarity index 100% rename from screenids.h rename to Ja2/screenids.h diff --git a/ub_config.cpp b/Ja2/ub_config.cpp similarity index 100% rename from ub_config.cpp rename to Ja2/ub_config.cpp diff --git a/ub_config.h b/Ja2/ub_config.h similarity index 100% rename from ub_config.h rename to Ja2/ub_config.h diff --git a/Laptop/Encyclopedia_Data_new.cpp b/Laptop/Encyclopedia_Data_new.cpp index 5de9ac67..2dff5b82 100644 --- a/Laptop/Encyclopedia_Data_new.cpp +++ b/Laptop/Encyclopedia_Data_new.cpp @@ -21,7 +21,7 @@ #include "QuestText.h" //quest: name #include "laptop.h" //ui positions #include "Utilities.h" - #include "Utils/Cursors.h" + #include "Cursors.h" #include "sysutil.h" //extra Buffer for scaling image #include "vsurface.h" //fill extra buffer with black color #include "Text.h" diff --git a/Laptop/Encyclopedia_new.cpp b/Laptop/Encyclopedia_new.cpp index e1c5ac39..08596e8c 100644 --- a/Laptop/Encyclopedia_new.cpp +++ b/Laptop/Encyclopedia_new.cpp @@ -36,7 +36,7 @@ #include "laptop.h"//UI dimensions, mouse regions #include "Utilities.h"//file names #include "vobject.h"//video objects - #include "Utils/Cursors.h" + #include "Cursors.h" #include "Text.h"//button text #include "Button System.h" #include "Encyclopedia_new.h" diff --git a/Multiplayer/CMakeLists.txt b/Multiplayer/CMakeLists.txt new file mode 100644 index 00000000..e48f407f --- /dev/null +++ b/Multiplayer/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(Multiplayer +"client.cpp" +"server.cpp" +"transfer_rules.cpp" +) +target_include_directories(Multiplayer PUBLIC +${CMAKE_CURRENT_SOURCE_DIR} +"raknet" +) +target_link_libraries(Multiplayer PRIVATE +"${CMAKE_CURRENT_SOURCE_DIR}/raknet/RakNetLibStatic.lib" +) 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/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/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