PDA

View Full Version : Luna Game Library - Simple & Elegant Game Programming



drezgames
17-04-2017, 04:42 AM
1495

Luna Game Library - Simple & Elegant Game Programming

DOWNLOAD (https://goo.gl/3V2QSF) (2017.2.Alpha, 57.3MB - 2017/11/05)

OVERVIEW
Luna Game Library™ (LGL) is a 2D game library for PC's running Microsoft Windows® and uses Direct3D® for hardware accelerated rendering. It's robust, designed for easy use and suitable for making all types of 2D games and other graphic simulations.

You access the features from a simple and intuitive procedural API (Luna.API) to allow you to rapidly and efficiently develop your graphics simulations. There is support for buffers, textures, sprites, sound, archives, tweeting, IAP, databases, remote highscores, video playback and much more.

You can also use the thin, object oriented framework (Luna.Framework) to manage your game projects in a more structured, oop manner. You can define your game in terms of actors, where these actors live and are managed on an actor list. These actors can interact by sending messages and do collisions. All of this can be encapsulated into an application using the game class.

FEATURES
- Made in Delphi, for Delphi developers
- Procedural low-level access plus higher level thin oop framework.
- Uses SDL2 2D hardware rendering.
- Uses 32bit surfaces and textures.
- Free scaling, rotation, alpha blending and other special effects.
- Windowed and fullscreen desktop modes.
- Frame based timing support.
- Memory mapped buffer support
- Zip archive support (resourced loaded from archive or file system)
- TrueType font support
- Graphic primitives (lines, circles, rects, points).
- Advanced polygon rendering (scale, rotate, control line segment visibility).
- Advanced sprite management.
- Polypoint collision system for fast precise collision detection.
- Mouse and keyboard input management.
- Unified audio system with support for WAV | MP3 | MID | OGG | MOD | IT | S3M | XM music formats.
- Comprehensive math routines (vectors, angles, line intersection, clipping).
- Log file support.
- SQL database support (MySQL local & remote | SQLite local only).
- High-level support for Entities.
- Networking (reliable UDP) with support for object persistence.
- Tweet (with media) directly to a twitter account
- IAP support (in-app purchase using stripe.com)
- Includes LunaArc, an archive utility for making compressed zip archives for use in your game.

Cybermonkey
17-04-2017, 08:30 AM
Looks interesting (reminds me a bit of Pulsar2D ;)). Hope to see some live demos soon. According to your logo, do you plan to integrate Lua support?

drezgames
17-04-2017, 02:49 PM
Sup bro. How have you been? Hope all is well. Thanks. Yea, I forgot to mention (sorry about that) was also inspired by your projects as well. I will be working on examples and things this week. Oh, hehe, in the very beginning I had the idea of Lua integration thus the name/logo. Delphi starter is now free so it became less of a priority. Maybe at some point I may or if someone does it first.

Cybermonkey
18-04-2017, 06:05 PM
Thanks, I am fine (again...). Anyway, I am also still interested in your pascal wrapper for raylib. ;)

drezgames
18-04-2017, 09:20 PM
Oh yea, sorry I forgot. See your PM.

drezgames
23-04-2017, 01:55 AM
New features added since last post:
- Further refined the highscore code
- Local and remote database support (local=SQLite3, remote=MySQL, unified as Database and DatabaseTable objecgts)
- Polygon object
- Polypoint auto-trace (can trace a sprite and apply a polygon around it. This will be used for fast polypoint collision detection)
- Sprite object (can be organized as pages (texture) and images can be defined in grid or rect format)
- FrameSpeed can be use to implement multiple timers in your project. For example you have the simulation running at 30 fps, but you want your sprite animation to update at 15 fps, you can do:

if FrameSpeed(mytimer, 15) then
begin
...
end;
- FastText can now define a range of glyphs. For example 32-127, 'tm', '(c)' are automatically defined by default. Since the unicode range is HUGE i'm using a sparse array to manage the glyphs range. It's very efficient.

Planned features to come:
- Entity object (instance of a sprite, has position, can do collision, etc)
- Actor object (instance of an entity, can live on a scene object in the game world, etc)
- State machine for actors
- More...

drezgames
23-04-2017, 03:32 PM
I'm using frame-based timing in the library. I wanted to have an efficient way to do timing where rendering and updating where decoupled and your simulation is controlled as much as possible. Ideally if your game loop can run as fast as possible while your simulation ran at a known and predictable would give your the overall best visual experience.

I expose two main routines for this: SetTargetFrameRate and GetDeltaTime. Call SetTargetFrameRate to 30, 60 fps for example and then when you call GetDeltaTime it will return a value that when you multiply by your object's speed, will try and keep them moving at the target frame rate. For example, if your game loop speed was 60 fps, GetDeltaTime would return 0.5. The timing code automatically handles and smooths out large delta time values and prevents large spikes. The end result is silky smooth motion where updating and rendering are decoupled. You get the best possible over visuals while keeping your simulation running at a known and predictable rate.

Physics, on the other hand needs to run at fixed rates. When I eventually get around to adding physics support I will then also add support for this also.

drezgames
29-04-2017, 03:42 AM
I finally got website up. https://2drealms.com/.

Progress continues... adding edities, scene, statemachine etc. I was looking at some very old code today and notice this certain section was just wrong. Doh! The way it was implemented in the old code base I never had any apparent problems. Hehe. But when I came across it, I could instantly see it was not correct. Made the correction and it works as expected in the new code base. Amazing. I've not looked at some of this code in 10-15 years and I am able to go right in and work with it.

drezgames
30-04-2017, 02:18 AM
Got polypoint collision detection in now. Did some test last night and I'm confident that I can get IAP (in-app purchase) integrated. For the moment, the only payment gateway will be Strip. Strip is super easy to setup and configure without all the troubles that you go through with most gateways. At the moment the fees are (2.9% + 0.30) per transaction. The process payment call will be asynchronous, calling a user defined event routine with status updates. Cool, excited to see how this works out.

drezgames
30-04-2017, 10:17 PM
Ok, IAP is now in. I got it down to these minimal routines:



//---------------------------------------------------------------------------
// In App Purchase
//---------------------------------------------------------------------------
procedure IAPSale(
// processing
aAPIKey : PChar;
aEvent : TIAPEvent;

// transaction
aTransactionAmount: PChar;
aTransactionDesc : PChar;

// credit card
aCardCVVData : PChar;
aCardExpMonth : Integer;
aCardExpYear : Integer;
aCardNumber : PChar;

// customer
aCustomerFirstName: PChar;
aCustomerLastName : PChar;
aCustomerAddress : PChar;
aCustomerCity : PChar;
aCustomerState : PChar;
aCustomerZip : PChar;
aCustomerCountry : Pchar;
aCustomerEmail : PChar;
aCustomerPhone : PChar
); stdcall; external LUNA_DLL;
function GetIAPResponseApproved: Boolean; stdcall; external LUNA_DLL;
function GetIAPResponseApprovalCode: PChar; stdcall; external LUNA_DLL;
function GetIAPResponseAVSResult: PChar; stdcall; external LUNA_DLL;
function GetIAPResponseCode: PChar; stdcall; external LUNA_DLL;
function GetIAPResponseCVVResult: PChar; stdcall; external LUNA_DLL;
function GetIAPResponseInvoiceNumber: PChar; stdcall; external LUNA_DLL;
function GetIAPResponseText: PChar; stdcall; external LUNA_DLL;
function GetIAPResponseTransactionId: PChar; stdcall; external LUNA_DLL;

When you call IAPSale, the operation will be pushed into a background thread. When completed the aEvent routine will be called and you can then check the results with the GetIAPResponseXXX routines. If the transaction was approved GetIAPResponseApproved will be true and the transaction id (which is needed for refunds etc) will be returned. When testing, simply use your test API key you get from stripe. For a real purchase use the live key.

Since you also have database support, you can store your data on a remote database, on the local filesystem, encrypted, etc., as simple or elaborate as you wish.

drezgames
21-05-2017, 08:00 PM
First public release (link will always be at top in 1st post)

It would be nice to get some feedback. Trying to get an idea of performance and how it works across different configurations. Comments/suggestions welcome.

Some feature in this release include:
- Frame-base timing
- Password protected archive (standard zip files)
- Vector math routines
- Memory mapped buffer object (uses file mapping so can be very large, the OS will manage swapping in/out of memory, you just access the pointer or the Read/Write methods of object)
- Kbd & mouse support
- Graphic primitives, viewports, polygons and textures
- True-type font support.
- Sprite support (can be organized into pages and groups) and has support for polypoint collision
- Entity (sprite with position and orientation, collision detection)
- Music and sound playback
- Video playback (.mpg only at this time)
- Screenshake support
- Screenshot system (can specify folder and base filename)
- Basic networking (fast UDP with reliable packets)
- Database support (SQLite and MySQL)
- Highscore system (or you can create your own with the database support)
- Twitter and IAP support
- 3D starfield
- Much more to come...

drezgames
24-05-2017, 03:26 AM
I now got devblog, forums, project tracker and downloads setup on the website (https://2drealms.com).

kostyap
24-05-2017, 04:25 AM
I now got devblog, forums, project tracker and downloads setup on the website (https://2drealms.com).

Tried to download. I't is only available to registered users. Tried to register few times and got "you did not pass security check" message

drezgames
24-05-2017, 04:42 AM
Hi, so sorry about that. Please try again, you should be able to download as guest now. I forgot to set the guest permissions. Can you please let me know what security msg your getting? Thanks.

drezgames
24-05-2017, 05:10 AM
@kostyap, ok everything should be working now. If you could be so kind, please also try to register again. The recaptcha should show up properly now. You will then get an email, click the link to validate and all should "just work". Again, sorry and thanks very much for reporting the issue. Between the last update, they changes some things and I had to reset and reconfigure a few items.

drezgames
25-05-2017, 05:24 PM
Basic physics coming soon. Hopefully in next build.8)

drezgames
26-05-2017, 03:59 AM
Now got basic physics in.

*** UPDATE ***

I removed the old physic engine, too unable. Will be adding a better one in the future.

Thyandyr
26-05-2017, 09:31 AM
You're on a hot streak of productivity.

Opens clean, compiles clean, examples work, except Polygon had 'invalid floating point operation'. All in all nice and clean like promised. 10 out of 10 would try again!

drezgames
26-05-2017, 03:32 PM
@Thyandyr, hey thanks man and thanks for the feedback. I appreciate it. Did you get the error right away or did you see it rotate a bit first?

Yea, trying to get in all the features that I need for the series of games I want to make using LGL.

Again, bro, thanks. I will look into the floating point error.

Thyandyr
26-05-2017, 10:45 PM
@Thyandyr, hey thanks man and thanks for the feedback. I appreciate it. Did you get the error right away or did you see it rotate a bit first?


I tried it at work with 32 bit Windows 7 machine without graphics card. It failed straight away I saw nothing. I can maybe look at it Monday if I have time.

The same example works fine on my home computer, 64 bit windows 10 GTX 860M.

drezgames
26-05-2017, 11:17 PM
Yea, it will fail without a GPU. Everything rendered is hardware accelerated. Also, I do not have robust error checking in also at the moment. I've been trying to get the API finalized first. Then, in a future build, I will do a sweep and properly handle error conditions and gracefully return if possible. I was having some floating point issues with physics and I got that sorted out (hopefully :)), so maybe it will fix the issue you reported too as I think they steam from the same set of circumstances. Fix will be in the next build.

Oh, one nice feature I got in the current build is the TBuffer object. This is memory mapped and paging from disk is handled automatically. Large data files (levels, for example) can be access as if it was just a memory pointer. If the pointer reference you're currently accessing is on not in memory, it will page in transparently. NICE! You can access the pointer directly or use the position/read/write routines (its actually a TStream decedent).

Akira13
29-05-2017, 12:47 AM
Very cool. Nice demo project. Out of curiousity though, what exactly made you go with DirectX 9 for new development in 2017?

drezgames
29-05-2017, 01:25 AM
@Akira13, thanks. Ahh yea, that is the version of the chuck of rendering code that I pulled over from an another project. It's works and well tested so I stuck it in so that I can get the new API to a stable point. Then I can go back later and swap out/upgrade etc.

drezgames
29-05-2017, 04:16 AM
*** UPDATE ****
Removed the scripting engine for now. Too unable. I hope to add something better in the future.


Okay, so I got the scripting system implemented. It can compile Delphi 7 level syntax to 32 bit native code. You can run the whole script and/or call a script routine, create a script class instance and call its methods. Be in next build. ��


function Script_Create: TScript; stdcall; external LGL_DLL;
procedure Script_Destroy(var aScript: TScript); stdcall; external LGL_DLL;
procedure Script_Reset(aScript: TScript); stdcall; external LGL_DLL;
function Script_Compile(aScript: TScript; aArchive: TArchive; aFilename: PChar): Boolean; stdcall; external LGL_DLL;
function Script_ErrorCount(aScript: TScript): Integer; stdcall; external LGL_DLL;
function Script_WarningCount(aScript: TScript): Integer; stdcall; external LGL_DLL;
function Script_ErrorMessage(aScript: TScript; aIndex: Integer): PChar; stdcall; external LGL_DLL;
function Script_WarningMessage(aScript: TScript; aIndex: Integer): PChar; stdcall; external LGL_DLL;
procedure Script_SaveProgram(aScript: TScript; aFilename: PChar); stdcall; external LGL_DLL;
procedure Script_Run(aScript: TScript); stdcall; external LGL_DLL;
function Script_CallRoutine(aScript: TScript; aFullname: PChar; aParamList: array of OleVariant): OleVariant; stdcall; external LGL_DLL;
function Script_CreateObject(aScript: TScript; aClassName: PChar; aParamList: array of const): TObject; stdcall; external LGL_DLL;
procedure Script_DestroyObject(aScript: TScript; aObject: TObject); stdcall; external LGL_DLL;
function Script_CallMethod(aScript: TScript; aFullname: PChar; aInstance: TObject; aParamList: array of OleVariant): OleVariant; stdcall; external LGL_DLL;
function Script_GetAddress(aScript: TScript; aFullname: PChar): Pointer; stdcall; external LGL_DLL;
procedure Script_SetCompileEvent(aScript: TScript; aEvent: TScriptCompileEvent); stdcall; external LGL_DLL;
function Script_CompileEvent(aScript: TScript): TScriptCompileEvent; stdcall; external LGL_DLL;

Thyandyr
29-05-2017, 08:23 AM
That is very interesting. Looking forward to examples/demo/etc. Check out BCEditor in case you need nice syntax highlighting.

drezgames
29-05-2017, 07:18 PM
That is very interesting. Looking forward to examples/demo/etc. Check out BCEditor in case you need nice syntax highlighting.
Hey thanks. I will check out BCEditor!

drezgames
30-05-2017, 02:36 AM
Fixed in this release:


Database type ID where mission in the API binding header
Added fix for floating point operation exception

Added in this release:


Allow PolyPoint collision check with a point (suggested by Jon Souter)
Added basic physics + example
Added scripting support + examples
Reorganized the Examples menu into Native and Script sub menus
General fixes and improvements

Thyandyr
30-05-2017, 09:18 AM
The new examples start fine, but I get something called "Non user breakpoint" if I hit F12 on script examples or drop too many physics items. Again, I'm at work computer without graphics card.

drezgames
30-05-2017, 03:01 PM
The new examples start fine, but I get something called "Non user breakpoint" if I hit F12 on script examples or drop too many physics items. Again, I'm at work computer without graphics card.
Hi, thanks for the report. Rem too it needs a Direct3D compliant 3D video to work property. Are you running the example standalone or from within an IDE with the debugger? I've noticed I get this ever so often when I run in debug mode. The physics run in a background thread and the debugger I think interferes with it somehow and/or I need to check for more areas for thread safety. I found and fixed a few more areas for this release. Still investigating. Again, thanks.

Thyandyr
30-05-2017, 03:18 PM
OK that makes sense. I never had that before. And it is only happens in Debug mode as you said.

Akira13
01-06-2017, 01:58 AM
Haha, It just hit me that this engine is obviously an updated version of Hadron. Good to see it make a comeback, I always thought it looked quite promising at the time...

drezgames
01-06-2017, 02:19 AM
Haha, It just hit me that this engine is obviously an updated version of Hadron. Good to see it make a comeback, I always thought it looked quite promising at the time...
Hi, thanks. I was able to pull a lot the code over. I could benefit from all the well tested code that had some mileage. The lower-level code is new and all the new features that has been added that I did not get a chance to add before (video, iap, working highscore, physics, the threaded architecture, etc). I'm currently testing an immediate mode GUI system. Hopefully I can get it in a future build.

drezgames
03-06-2017, 07:24 PM
*** UPDATE ***
I removed the IDE stuff, it will be in a separate project.

What I have planned for next build is to include a stand alone command line compiler (Luna Pascal Compiler), that can create 32 bit EXEs and DLLs. It will use what i'm calling "project directives" to specify project options. This makes the main project source file self subscribing and in keeping with the simple & elegant theme of LGL. The following project options are in and working:


{$REGION 'Project Directives'}
// Project Directives: General
{$CONSOLEAPP} // Output a console application
{$MODULEOUTPATH "path"} // Output module in bin folder
{$EXEICON "iconfile[.ico]"} // EXE Icon filename
{$SEARCHPATH "path1;path2;path3" // Source Search Paths


// Project Directives: VersionInfo
{$ADDVERSIONINFO} // Add VersionInfo below
{$COMPANYNAME "Company Name"} // Company Name
{$FILEVERSION "1.0.0.0"} // File Version
{$FILEDESCRIPTION "File Description"}
{$INTERNALNAME "Internal Name"}
{$LEGALCOPYRIGHT "Legal Copyright"}
{$LEGALTRADEMARK "Legal Trademark"}
{$ORIGINALFILENAME "Original Filename"}
{$PRODUCTNAME "Product Name"}
{$PRODUCTVERSION "1.0.0.0"} // Product Version
{$COMMENTS "comments"}
{$ENDREGION}

program Test;

uses
SysUtils,
LGL;

begin
...
end.

drezgames
04-06-2017, 12:00 AM
*** UPDATE ***
I removed the IDE stuff, it will be in a separate project.

**************

A peek at the IDE i'm working on for the compiler.

1467

drezgames
04-06-2017, 03:17 AM
*** UPDATE ***
I removed the IDE stuff, it will be in a separate project.

**************


Some features working so far (param hints, code completion, etc):

drezgames
05-06-2017, 06:21 AM
*** UPDATE ***
I removed the IDE stuff, it will be in a separate project.

**************


IDE Styles (WIP)

turrican
05-06-2017, 10:48 AM
Will you support android?

drezgames
05-06-2017, 04:28 PM
Will you support android?
Hi, in the very near term, no. After I get the API stable, the mid to long term goal is to support more platforms.

turrican
05-06-2017, 05:01 PM
Will you support android?

Nice! If you need help on run with android linux I can help you. ZenGL is one of the best examples to follow :)

drezgames
05-06-2017, 08:28 PM
Nice! If you need help on run with android linux I can help you. ZenGL is one of the best examples to follow :)
NICE! Cool bro, thanks so much! 8)

drezgames
07-06-2017, 06:06 PM
- Renamad Highscore_SetOnThreadEvent to Highscore_SetThreadEvent (naming consistency)
- Renamed Highscore_GetOnThreadEvent to Highscore_ThreadEvent (naming consistency)
- Added Luna Game Pascal and light-weight IDE (lgPascal, multi-projects, EXEs and DLLs, single-file project format, custom skins)
- Delphi and Luna Game Pascal examples
- Rename makerez to lgRez for naming consistency
- General fixes and improvements

Thyandyr
24-10-2017, 08:39 PM
I wasn't much active during the summer. Any updates?

drezgames
24-10-2017, 08:48 PM
Hi, yes. I'm working on new build coming soon'ish.

drezgames
26-10-2017, 04:03 PM
@Thyandyr, I basically rewrote a large chunk of it over the summer. More efficient structure, some optimizations, bug fixes, etc. I now have a consistent naming convention for the API and got the header documented. The new build is not ready just yet, but if you want to take a look at the header and the current feature set, you can view here (https://1drv.ms/u/s!AuufJLjg6CUXjnzzQ4HA50agjFSd). I removed physics and scripting for now. They were too unstable. I hope to add them back in a future build. Hopefully in the next few days I will have new build ready and get this thread updated with new info, images and videos.

Thyandyr
26-10-2017, 07:12 PM
It has lot of stuff going on! In game purchases! Twitter! It's cool how it can set up the highscore database remotely.

Trivial typos on lines 821, 1055, 1111

Besides for making games with this, I can see how this can be used as drop in replacement for bass.dll and for other supportive features in games.

drezgames
26-10-2017, 09:37 PM
It has lot of stuff going on! In game purchases! Twitter! It's cool how it can set up the highscore database remotely.

Trivial typos on lines 821, 1055, 1111

Besides for making games with this, I can see how this can be used as drop in replacement for bass.dll and for other supportive features in games.
Thx. Yes, all the thing that I need (hopefully for others too) for my typical game project, simple and easy to use.

Ahh yes, thanks for catching those typos.

Thyandyr
31-10-2017, 10:05 AM
One feature that may be useful for music files is to start from a specific location.

procedure Music_Play(aMusic: TMusic; aVolume: Single; aLoops: Integer; aLocation: Single = 0); external LUNA_DLL; // Playback music starting from aLocation

Specified in seconds, percent of file length etc.

drezgames
31-10-2017, 04:33 PM
One feature that may be useful for music files is to start from a specific location.

procedure Music_Play(aMusic: TMusic; aVolume: Single; aLoops: Integer; aLocation: Single = 0); external LUNA_DLL; // Playback music starting from aLocation

Specified in seconds, percent of file length etc.

Ahh, great suggestion. I think I should be able to add this. Cool, thx.

drezgames
01-11-2017, 03:03 AM
One feature that may be useful for music files is to start from a specific location.

procedure Music_Play(aMusic: TMusic; aVolume: Single; aLoops: Integer; aLocation: Single = 0); external LUNA_DLL; // Playback music starting from aLocation

Specified in seconds, percent of file length etc.

Ok, added:

function Music_SetPosition(aPosition: Single): Boolean; external LUNA_DLL; // Set the current position (seconds) in the music stream (only MOD, OGG, FLAC, MP3_MAD, MODPLUG formats).

Will be in next update. Thanks again for the suggestion.

drezgames
04-11-2017, 06:47 PM
*** UPDATE ***
- cleaned up thread, removed old media and provided update status on certain features
- removed physics (too unstable, new version in the future)
- removed scripting (too unable, not sure if I will add in the future)
- removed ide stuff (will be in separate future project)
- fixed, enhanced and made some internal optimizations (texture blending modes, enable/disable vsync, Luna.Framework, etc)
- adding some more complex demos (see videos below)
- new build coming soon(ish)tm

Elastic Demo

https://youtu.be/VT36899pTzY

Viewports Demo

https://youtu.be/YCA143rkNoA

Scroll Demo

https://youtu.be/-XAi--D6VtY

AstroBlaster Mini Game

https://youtu.be/oaHiJKRd5F0

ChainAction Mini Game

https://youtu.be/ymn3w2smtUg

drezgames
05-11-2017, 07:21 PM
New build released. Link in the 1st post.

Pascal
27-11-2017, 01:59 AM
Demos are pretty cool. I think more people would be interested if it supported Lazarus though. Not that many people really have Delphi anymore I don't think... too expensive.

drezgames
27-11-2017, 02:16 AM
Hi, thx.

New version coming (hopefully soon'ish) that will work with FPC, Delphi (there is a free version of Delphi now days) and there will be a new IDE, I'm working on. I totally rewrote the whole code base for the IDE, lots of changes and great features. No external dependencies (don't have to have Delphi/FPC installed).

1500