Results 1 to 10 of 42

Thread: SvPascal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    How can I disable that Escape quits the game. And how can I make sure that 'Alt' won't make the window loose focus so I can actually use that button in a game?
    I've tried to overwrite UpdateInput(a: Single) without calling inherited but that doesn't change anything.
    Last edited by pstudio; 16-07-2011 at 05:38 PM.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  2. #2
    simvector
    Guest
    Hi,

    1) Override TSvPrototypeGame.ProcessTerminate; By default it does this:
    Code:
    procedure TSvPrototypeGame.ProcessTerminate;
    begin
      // ESC key terminated by default
      if SV.Input.KeyHit(Key_Escape) then
      begin
        Terminated := True;
      end;
    end;
    2) You can get the KEY_LALT and/or the KEY_RALT keys but pressing ALT by itself will cause the window to loose the input focus. I have the system menu attribute added to the app window (so an icon can display) and I thinking maybe this is what's grabbing the focus. Pressing ALT will usually activate the window's menu.

    You can override and capture ALT like what I've done below. I tried to call Win32 SetFocus but it does not seem to work. I will have to look into this. I never use ALT (alway in combination with another key) by itself is why I guess I've never ran into this issue.


    Code:
    function SetFocus(hWnd: Cardinal): Cardinal; stdcall; external 'User32.dll';
    
    type
    
      TGame = class(TSvPrototypeGame)
      public
        procedure UpdateInput(aElapsedTime: single); override;
      end;
    
    procedure TGame.UpdateInput(aElapsedTime: single);
    begin
      inherited;
      if SV.Input.KeyHit(KEY_LALT) then
      begin
        Title := 'Jarrod';
        SetFocus(SV.DisplayDevice.Handle);
      end;
    end;
    Thanks for reporting.
    Last edited by simvector; 16-07-2011 at 08:07 PM.

  3. #3
    Ok, I'll look into it,

    another question: how do I get the absolute application path in SvPascal?
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  4. #4
    simvector
    Guest
    You can do this for now:
    Code:
    function GetModuleFileNameW(Module: Integer; Filename: PWideChar;
      Size: Integer): Integer; stdcall; external 'kernel32.dll';
    
    function SvStartupPath: string;
    var
      Buffer: array[0..260] of WideChar;
      i: Integer;
    begin
      Result := '';
      GetModuleFileNameW(0, Buffer, 260);
      for i := 0 to 260 do
      begin
        if Buffer[i] = #0 then
          break
        else
          Result := Result + Buffer[i];
      end;
      Result := ExtractFilePath(Result);
    end;
    You have to copy the buffer this way ATM until I get string conversion working properly.

  5. #5
    wow, seems more invovled than I would have expected . I'm gonna check it out now.

    Could you list the order of how things are rendered in TSvPrototypeGame.
    Right now it seems the TSvRenderScene.Render is called before TSvAIStateMachine.Render but I need it the other way round. I decided to use the state machine as a quick implementation for game screens. The result is that my background is drawn on top of the entities in the game.
    My guess is that I'll have to make my own implementation of RenderFrame in TSvPrototypeGame so I would like to now which things are called in it so that I don't forget to call some render function.
    Imagine I've written something clever here inspiring you to make something awesome. If that happens give me credits

  6. #6
    simvector
    Guest
    This is what ParamStr(0) does with the exception of the loop. In the end I will simply bind to ParamStr but in the current build this is not done so the only way to do it is to call on win32 to do it. The good thing is that SvPascal is able to do it in it's current state. I was pleasantly surprised that I actually got it to work. Normally you can typecast the buffer array to string which is currently not working correctly. So I had to loop and copy the buffer.

    SvPascal binds directly to SvEngine.pas and SvEngineFramework.pas (SvEngine, bindings folder) so you can view directly what's going on from those units. Here is the current implementation:
    Code:
    procedure TSvPrototypeGame.RenderFrame;
    begin
      FScene.Render(FSceneAttr);
      FStateMachine.Render;
    end;
    You can override renderframe like this:
    Code:
    procedure TMyGame.RenderFrame;
    begin
      StateMachine.Render;
      Scene.Render(SceneAttr);
    end;
    You can also take advantage of the attribute feature and tell Scene.Render to only render specific objects with attributes set. Each TSvObject can have up to 256 attributes, numbered from 0-255. They can be on/off. So player can be 0, enemy can be 1, rocks 2 and so on. If you do not want to render anything, set MyGame.SceneAttr := [255] for example and nothing will be rendered in this case. If you only want to update certain object and not others, just tell game which ones and only they will render/update.

    Glad to see you trying the AI stuff. What I've implemented is what I call an event driven state machine. Makes it very easy to organize your game into be and ran by states. I'm currently working on a game project that will be using them also. My goal for this game project is to make the code very data driven and build a level editor around it. I will be taking advantage of component based design. SvEngine framework is built around this principle already. Actors have children which can update/render, can have a state machine and the game classes has a state machine for use at the upper level.
    Last edited by simvector; 16-07-2011 at 11:51 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •