Miscelaneous programs, simulations, algorithms and tests. Mainly with Free
Pascal using cCHXSDL3Engine.
This repository has unsorted programs with miscellaneous small little projects: Fractals, Minigames, Simulations, Data Structures visualization, and other experiments.
The basic directory structure of Metaformática is:
CHANGELOG.md: Full change log.LastChanges.md: Last changes commited to the repository.NewProject.sh: Script to create structure for a new program.README.md: This text.0Base/: Template structure for programs (to be copied withNewProject.sh).README.md: Information about the program.build.shandBuild.bat: Created byNewProject.sh.bin/: Final program directory.{Executable}: Actual executable program (and dll).{OtherFolderOrFiles}: Whatever executable needs to run.
lib/: Where compiler will put compilation files.src/: Source directory.{MainProgram}.pasMain program(s) for compiling.fp.cfg: FPC config file for easy compiling.Units/: Directory with non common units used by the program.
res/,man/,doc/: Compilation recurses, User manual, Documentation, &c; if exists.
0Common/: Submodules and common units.Units/: Common units between programs but not in CHXPas or other submodule.CHXPas/: CHXPas repository as git submodule, wherecCHXSDL3Engineactually is.SDL3/: SDL3-for-Pascal submodule, used bycCHXSDL3Engine.
{Category}/{ProgramDir}/: Actual programs directory, each in its own folder.
Maybe, someday, all of above is under Pascal directory because programs in
other languages are added... (but surely I will try to port to Pascal).
Every project have a Build.{sh|bat} for easy compilation, but they only
creates output dirs, changes to src folder and execute:
fpc @fpMeta.cfg {MainFile}.pas
fpMeta.cfg sets directories for searching units and include files. FPC
parameters can be added to build.sh too, and -dRELEASE parameter creates
an optimized and striped executable.
Executable file will be created at bin directory, and it must run from
there.
On Windows, fpc compiler program is suposed to be in PATH enviroment
variable and executable's folder must have SDL3.dll (and other .dll if
needed) and be sure that they are for the compiled and system
architecture (32/64bits).
If Lazarus is used for compilation, maybe it's needed to add units folders manually to the project configuration.
cCHXSDL3Engine is a class very similar to GameEngine pattern. Two main
differences are very little anyways:
- Main Loop is divided in three methods:
Compute,DrawandHandleEvent. Nothing stops to use only one for all things, but have some differences:Computeis intended for algorithm computation. WithExitProgvariable can finish program execution by itself. Time spend inside it is monitorized bycCHXSDLFPSManager.Drawis for drawing of course. It's not called if the Window is minimized.HandleEventis called once per Event ocurred between frames. Some of then are automatically handled bycCHXSDL3Engineor its components.
- Order of the loop is
Compute,DrawandHandleEventwhile usually GameEngine pattern is to handle events first; and then compute and draw. In real time there is not difference at all. - Actually there are 2 other methods:
Setupis called once before entering the main loop for setting initial values, object creation, etc.Finishis called after exiting main loop for memory freeing or other finalization stuff.
Other classes and units are developed to help:
cCHXSDLWindow(Windowproperty inside of the engine) encapsulatesSDL_Windowand handles window events.cCHXSDLFrameManager(FPSMngproperty) keeps framerate constant with interpolation and stores some information related:FrameCounter,LastFrameTime(Total frame time) andLastCompTime(Last computation time).cCHXSDLRenderer(Renderproperty) encapsulatesSDL_Rendererand its primitive functions, and proporcionate more primitives to draw than vanilla SDL3 withoutSDL_gfxlibrary.cCHXSDLTypeHelpersis a unit with helpers for SDL types, operator overloads and some other useful types.
The engine uses SDL3-for-FreePascal project headers.