Log Viewer Source Code

From WinBolo

Revision as of 15:32, 1 December 2008 by John (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

It is available under the GNU GPL version 2 and available to download via Google code.

The Log Viewer application can be found under the winbolo/src/logviewer folder.


Contents

Requirements

  • Direct X 5
  • Windows MM Libraries (included in windows)
  • Winsock 2 (used for DNS lookups)

Compiling

Add all files from the src/logviewer and src/zlib directory to a windows application project. Add DirectDraw, DirectSound, Windows mulitmedia and winsock libraries to the project.

Design

The Log viewer application shares the same design principle of WinBolo (as well as a lot of code) The application is split into two parts:

  • Backend - Manages the game world and processing the Log Files
  • Frontend - User interface and provides function callbacks for drawing and playing sound.

The backend is not thread safe and calls to the backend functions must be mutex locked.

Backend

The backend is accessed through screen.c. Functions provided by this file are:

Log file functions:

screenLoadMap() - Loads a log file
screenCloseLog() - Closes a log file
screenFastForward() - Fast forward 
screenRewind() - Rewind back to previous snapshot
screenLogTick() - Advance one game tick

Drawing functions:

screenUpdate()- Refresh the main screen or move the screens map position
screenRequestUpdate() - Called periodically (once a second) updating item window status
screenSetSizeX() - Number of map squares wide of data requested by screenUpdate()
screenSetSizeY() - Number of map squares wide of data requested by screenUpdate()

Misc functions:

screenGetGameTimeLeft()
screenGetGameStartDelay()
screenGetTime() - Gets the current game time formated as a MM:SS string
screenCentreOnSelectedItem()
screenGetMapName()
screenTankCentred() - Keep centred on the tank
screenSaveMap() - Saves the map file at the current state


Front End

The following functions must be provided by the front end as they are called back by the backend as part of various requests.

frontEndDrawMainScreen()
frontEndPlaySound()
startOfLog()
windowRemoveEvents() - Remove events in the game messages window. May be called by rewind.
frontEndSetGameInformation()

main.c provide the entry point to the application.

Notes

The most interesting part of this code is the blocks.c file which is part of the backend.

Logs are read sequentially from the zip file. zlib does not provide a function for unreading data or moving backwards through the file. Every time a log file is moved back a snapshot the zip file needed to be closed then reopened and the file reread to the log file position.

blocks.c abstracts away access to zip file. It provides a linked list of memory each 512K in size. As the zip file is read it is cached into the memory blocks until the maximum cache memory is used up. At this point it starts deleting blocks as far as away from the current file position. If rewind it first tries to retrieve the data from the cached memory. If it is too far from the current position the cache is destroyed and the zip file reload process must occur. The cache starts building from that point.

blocks.c also XOR's the data before returning it ready for processing.

Personal tools