Jump to content

Hedge Hunter | Engine/Game/Benchmark


AdmiralAlkex
 Share

Recommended Posts

So I wanted to create a simple game that could use both GDI+ and SDL to render the graphics, but I ended up splitting the graphical stuff to it's own library.

What does it do?

  • It presents a uniform way to talk to GDI+ or SDL, by hiding some ugly implementation details along the way.

How to use it?

  • Download Hedge Engine:

    Hedge Engine v14.1.zip

    It contains all files necessary to run the included examples with all three renderers.

  • Run and learn from the examples + see comments in "#region ;Functions YOU should use"

What does it do again?

  • Can draw graphics with SDL, GDI+ or GDI+wSDL (GDI+ with SDL to blit to screen).
  • "Seamless" switching between all three.
  • Checks if x64 enabled/certain dll files is missing and disables SDL/GDI+wSDL if a requirement is missing. Note that helper dll's to SDL_image are not checked if they exist (because you probably don't need all), so if the SDL renderer crashes when loading a image see comments for _HedgeAddAsset() on what is needed (get dll's from or whatever).
  • A large part of the functions accept filenames as an alternative of pointers.

    This is done by saving the string used with _HedgeAddAsset(), and looping through them if a function gets a filename. If the asset isn't already loaded it is loaded and discarded immediately after use.

What ugly implementation details were hidden?

  • When GDI+ and SDL went in different directions (like graphics/bitmaps vs surface) the SDL way was often preferred. Examples of that would be double-buffering GDI+ to reduce flicker, and registering WM_PAINT to automatically redraw stuff when needed (neither of these are problems in SDL). This give SDL a potential advantage, as it's code is simpler and 25-35% fewer lines long.

Problems?

  • Should be few.
  • "Hedge Example Font.au3" crashes with GDI+
  • No support for MustDeclareVars (as SDL lacks that too)

Future?

  • I have some improvements and ideas I would like to implement, but this isn't high priority so don't know when. Besides, this kinda works decently enough right now.

Beta?

Hedge Engine v14.9.zip

(write over files from 14.1)

  • Fixes whatever it was that broke "Hedge Example Font.au3" with GDI+
  • Implements a series of primitives, partial flipping, saving surface to bmp and zoom
Edited by AdmiralAlkex
Link to comment
Share on other sites

good job... i have a few ideas for the future using this.

I attach a useful link http://www.libsdl.org/

EDIT: Maybe is the _ispressed method but is too bugged, it have to much delay and works rarely. I know that SDL have Ways to Check for inputs, or maybe the best solution is creating a hook of the keyboard or using adlibfunction to check the state of keys.

BTW :mellow:

Edited by monoscout999
Link to comment
Share on other sites

Hedge Hunter is telling me that

Hedge: SDL is unavailable, automatically switching over to: GDI+

Hedge: GDI+ initiating

Even though I have the files and such required

SDL won't run in x64-mode.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

It's a good start... why not make him duck to get under objects? Also maybe an animation when he runs in to something? :)

I will think about it, but my Paint(.NET) skills suck so it would look really nice (huh?) :)

good job... i have a few ideas for the future using this.

I attach a useful link http://www.libsdl.org/

EDIT: Maybe is the _ispressed method but is too bugged, it have to much delay and works rarely. I know that SDL have Ways to Check for inputs, or maybe the best solution is creating a hook of the keyboard or using adlibfunction to check the state of keys.

BTW :)

Thank you. When writing the SDL UDF I looked at keyboard input, it looked a bit overwhelming so I skipped it. I could probably do it now though, I already used it in Python so I kinda know how it should work.

But that would be for the SDL UDF, not Hedge because it need to work with GDI+.

Also while writing this I got a couple of ideas for how it could work (SDL/GDI+ irrelevant), so maybe I will try anyway (no promises!) :mellow:

SDL won't run in x64-mode.

Yep, only x86 dll's are readily available for SDL 1.2.

Which, BTW, is fixable. There's x64 support in SDL 1.3, only problem is that it would require a [rage on] COMPLETE FUCKING UDF REWRITE DAMNIT STOP STARING AT ME YOU FUCKING CYCLOPS CAT!! [rage off].

And I don't know if I want to do all that again by myself. Group project anyone? I imagine it would be designed as a proper UDF this time, not some personal playground for me that can't even do MustDeclareVars without major edits.

Thanks I just stuck

#AutoIt3Wrapper_UseX64=n

at the top and all is good.

Nice AdmiralAlkex, I will be implementing this into the terrain generator and make a side scroll "mario type of game"

That sounds really cool :party:
Link to comment
Share on other sites

  • 2 weeks later...

Also while writing this I got a couple of ideas for how it could work (SDL/GDI+ irrelevant), so maybe I will try anyway (no promises!) :mellow:

That wasn't actually hard at all*. Here's an example based on Hedge Hunter v7 with the internal label subclassed so we can spy on $WM_KEYDOWN and $WM_KEYUP. I may include this in Hedge Engine later, then I should be able to use it for checking $WM_PAINT also, so I don't need to use GUIRegisterMsg().

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=n
;~ #AutoIt3Wrapper_Run_Debug_Mode=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.6.1
Author:      Alexander Samuelsson (AdmiralAlkex)
Script Function:
Simple running game.
Credits:
UDF: AdmiralAlkex
Game-code: AdmiralAlkex
Graphics: AdmiralAlkex
Proving that GDI+wSDL is possible: monoceres
ToDo:
#ce ----------------------------------------------------------------------------
#Include "Hedge Engine.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include "SDL_gfx.au3"
#include <Constants.au3>
 
$hGuiMain = GUICreate(StringTrimRight(@ScriptName, 4), 400, 330)
$hButton = GUICtrlCreateButton("Change rendering library", 5, 5, 150, 20)
GUISetState()
 
$pScreen = _HedgeInitRender(1, $hGuiMain, 0, 30, 400, 300)
GUICtrlSetState(-1, $GUI_FOCUS)   ;Give focus to the label used internally by Hedge
$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))   ;Subclass the control
$iBackground = _HedgeAddAsset(@ScriptDir & "\Graphics\BackgroundM.png")
Local $iWalk[2]
$iWalk[0] = _HedgeAddAsset(@ScriptDir & "\Graphics\Walk1.png")
$iWalk[1] = _HedgeAddAsset(@ScriptDir & "\Graphics\Walk2.png")
$iJump = _HedgeAddAsset(@ScriptDir & "\Graphics\Jump.png")
Local $iTrap[3]
$iTrap[0] = _HedgeAddAsset(@ScriptDir & "\Graphics\Spikes.png")
$iTrap[1] = _HedgeAddAsset(@ScriptDir & "\Graphics\DeadCow.png")
$iTrap[2] = _HedgeAddAsset(@ScriptDir & "\Graphics\SmallGuyWithSword.png")
$iFont = _HedgeAddAsset(@ScriptDir & "\VeraMoBd.ttf", 18)
_SDL_Startup_gfx()
$StructFPS = DllStructCreate($tagSDL_FPSmanager)
_SDL_initFramerate($StructFPS)
_SDL_setFramerate($StructFPS, 30)
WinSetTitle($hGuiMain, "", StringTrimRight(@ScriptName, 4) & " Rendering with: " & _HedgeGetRenderName())
Local $iBackX = 0, $iUpTrue = False, $iTrapX = 0, $iTrap12 = 0
Global $Walk12 = 0
$pBack = _HedgeCreateSurface(800, 300)
_HedgeBlit($iBackground, $pBack, 0, 0, 800, 300, 0, 0)
_HedgeBlit($iTrap[$iTrap12], $pBack, 0, 0, 100, 100, 400, 200)
AdlibRegister("_AniPlayer")
Local $iTimerJump = TimerInit()
While True
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, $wProcOld)
   Exit
  Case $hButton
   _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, $wProcOld)
   _ChangeRendering()
   GUICtrlSetState(-1, $GUI_FOCUS)   ;Give focus to the label used internally by Hedge
   $wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
   $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
EndSwitch
_HedgeBlit($pBack, $pScreen, $iBackX, 0, 400, 300, 0, 0)
If $iBackX >= 400 Then _HedgeBlit($pBack, $pScreen, 0, 0, 400, 300, 800 - $iBackX, 0)
$iBackX += 6
If $iBackX >= 800 Then
  $iBackX = 0
  $iTrap12 += 1
  If $iTrap12 > UBound($iTrap) -1 Then $iTrap12 = 0
  _HedgeBlit($iBackground, $pBack, 0, 0, 800, 300, 0, 0)
  _HedgeBlit($iTrap[$iTrap12], $pBack, 0, 0, 100, 100, 400, 200)
EndIf
If _Keys(0x20) Then   ;Used like _IsPressed!
  If $iUpTrue = False And TimerDiff($iTimerJump) > 1500 Then
   $iUpTrue = True
   $iTimerJump = TimerInit()
   _HedgeBlit($iJump, $pScreen, 0, 0, 200, 200, 0, 0)
  ElseIf $iUpTrue = True And TimerDiff($iTimerJump) < 500 Then
   _HedgeBlit($iJump, $pScreen, 0, 0, 200, 200, 0, 0)
  Else
   $iUpTrue = False
   _HedgeBlit($iWalk[$Walk12], $pScreen, 0, 0, 200, 200, 0, 100)
  EndIf
Else
  $iUpTrue = False
  _HedgeBlit($iWalk[$Walk12], $pScreen, 0, 0, 200, 200, 0, 100)
EndIf
_HedgeDrawText($pScreen, $iFont, "$iBackX: " & $iBackX, 0xFF0000, 5, 5)
_HedgeFlip()
If $iBackX > 300 And $iBackX < 340 And $iUpTrue = False Then
  Sleep(1000)
  _WinAPI_SetWindowLong(GUICtrlGetHandle($__iHedge_Cid), $GWL_WNDPROC, $wProcOld)
  Exit
EndIf
_SDL_framerateDelay($StructFPS)
WEnd
Func _AniPlayer()
$Walk12 = Not $Walk12
EndFunc
Func _ChangeRendering()
$iAmount = _HedgeGetRenderMax()
$iCurrent = _HedgeGetRenderCurrent()
$iCurrent += 1
If $iCurrent > $iAmount Then $iCurrent = 1
_HedgeChangeRender($iCurrent)
_HedgeBlit($iBackground, $pBack, 0, 0, 800, 300, 0, 0)
_HedgeBlit($iTrap[$iTrap12], $pBack, 0, 0, 100, 100, 400, 200)
WinSetTitle($hGuiMain, "", StringTrimRight(@ScriptName, 4) & " Rendering with: " & _HedgeGetRenderName())
EndFunc
Func _Keys($iIndex, $iPressed = 2)
Static Local $aiKeys[256]
If @NumParams = 2 Then
  $aiKeys[$iIndex] = $iPressed
Else
  Return $aiKeys[$iIndex]
EndIf
EndFunc
Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
If $uiMsg = $WM_KEYDOWN Then
  ConsoleWrite(1 & @LF)
  _Keys($wParam, 1)
ElseIf $uiMsg = $WM_KEYUP Then
  ConsoleWrite(2 & @LF)
  _Keys($wParam, 0)
EndIf
;pass the unhandled messages to default WindowProc
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc

*Well, I didn't spend get arrow keys to work, so I changed jump to Space.

Edited by AdmiralAlkex
Link to comment
Share on other sites

Nice stuff but GDI+wSDL fail on x64 if I try to move the window.

You can't use GDI+wSDL on x64, aren't you running GDI+? Look at console. How is it failing? What is failing? What window? I need to know what code to run under which conditions so I can reproduce it.
Link to comment
Share on other sites

So you are running x86 AutoIt then. Good.

I don't remember any problem with moving windows. Are you using the 14.9 download? It is better.

If that doesn't fix it I need more details so I can reproduce this myself. Exact code, if you're using 14.1 or 14.9, EVERYTHING from console, and run this while you're at it:

MsgBox(0, "", "Is DWM on? " & (True = _DwmIsCompositionEnabled()) & @CRLF & "@error= " & @error)
Func _DwmIsCompositionEnabled()
$aRet = DllCall(@SystemDir & "\Dwmapi.dll", "long", "DwmIsCompositionEnabled", "int*", "")
If @error Then Return SetError(1, 0, 0)
Return $aRet[1]
EndFunc

And any other information you feel may apply.

One of those may give a clue.

Link to comment
Share on other sites

This is all I get in console.

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Administrator\Desktop\Hedge Engine v14.1\Hedge Demo.au3" /autoit3dir "C:\Program Files (x86)\AutoIt3" /UserParams

+>11:36:33 Starting AutoIt3Wrapper v.2.0.3.0 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X64 OS:X64)

>Running AU3Check (1.54.21.0) from:C:\Program Files (x86)\AutoIt3

+>11:36:34 AU3Check ended.rc:0

>Running:(3.3.7.14):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Documents and Settings\Administrator\Desktop\Hedge Engine v14.1\Hedge Demo.au3"

Hedge: GDI+wSDL initiating

Loaded SDL version: 1.2.14.*

Loaded SDL_image version: 1.2.7.*

Loaded SDL_TTF version: 2.0.9.*

!>11:36:47 AutoIT3.exe ended.rc:-1073741819

>Exit code: -1073741819 Time: 18.913

I use the last version I think v3.3.7.14.

And the function above fail because seems I don't have Dwmapi.dll in SystemDir. I tried to download manualy and call the function but I got an ugly error.

Posted Image

Edited by Andreik
Link to comment
Share on other sites

That dll is for Vista + only. You must be the only person in the world with x64 XP, that's not a popular mix :mellow:

But I am intrigued, I will try to look at it later tonight.

Link to comment
Share on other sites

Well, there's something really strange going on here. I got a copy of XP x64, installed on a VM and both SDL and GDI+wSDL crashes at _HedgeInitRender() due to DllOpen() failing!

This is some really fubar shit.

DllOpen() returns -1 even if I hardcode the path, but according to FileExist() (and my own damn eyes) the files is there! :)

Time to put on the old thinking hat...

:mellow:

Edit: was running "Hedge Example Font.au3" btw...

Edited by AdmiralAlkex
Link to comment
Share on other sites

  • 3 years later...
  • 5 months later...

I can't find _SDL_CreateRGBSurfaceFrom().  Doesn't seem to be in the SDL_UDF.

Is there anything I can do or is this topic too old?

@Xandy

It's in the sdl.au3 in the first post here. This was released after I had stopped actively developing the UDF so it's thread was never updated with the handful of functions made after that...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...