Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 31

Thread: Game Developement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    @Anton
    As far as I know the TickCount can be updated more than once per ms. I think that many newer computer already update tckCount every half millisecond.
    This means that variable T in your suggested code might not represent time taken in ms. Now it is possible to retrieve information from OS to see how often is TickCount updated so you can then properly calculate the time taken.

    Newer versions of Delphi also provides a special record called TStopWatch which tries to use the approach with best percision that is available on your computer. I have use it several times now for time profiling.

    But most of the times I simply go and store a time at the start of the process and another at the end and then check how much millisceconds did pas between them.
    Now you would probably say SilverWarior that approach doesn't provide good enough accuracy.
    That usually doesen't present a problem to me becouse if posible I tend to repeat certain procedure multiple times and check how much time is taken for that.
    Why am I doing so? Nowadays all computer support CPU autothrotling which can affect the test performance. Not to mention that you always have bunch of other processes running in the background which can consume veriable amounts of CPU power and greatly screw up your tests.

  2. #2
    So, let's see if i got it. Using that instruction that you gave me, i should be able to get the location of my file. It should be an ansistring right?
    And placing it instead of this <path name>, i should get something like this <path name>+'\data\file.bmp' right?
    Sorry if i get it bad, i just figured it out how much lack of knowledge i have in this think.
    Last edited by Realeg; 08-03-2015 at 07:02 PM.

  3. #3
    Method ExtractFilePath does include the TrailingPathDelimiter character so you don't need to add it in your string. This means that instead of

    Code:
    <path name>+'\data\file.bmp'


    you would use

    Code:
    <path name>+'data\file.bmp'


    As for the string type returned it is same string type that is the default string type of your development environment (AnsiString in Delphi 7, Unicode string in Delphi 2009 and newer, not sure for FPC/Lazarus thou).

    As for you being sorry about your lack of knowledge. Don't be. We all have been in your position once but we learned and so will you.
    Just don't be afraid to ask. The main purpose of this community is to help each other.

  4. #4
    Ok, it seems that my brain let me down. I simply can't figure out how to use the instruction. Can you give a concerete example if i need to get the path of file 'graphics.exe'?

  5. #5
    Is graphics.exe the executable of your application?

  6. #6
    Yes, an executable application has been build when i compiled the program, i presume that should be the executable from which i need to extract the path.

  7. #7
    My comment was very brief, to show very basic example of profiling.

    I'm not sure that GetTickCount actually gets a value from a hardware tick counter directly. At least in Delphi for Windows it is alias for WinApi function GetTickCount (https://msdn.microsoft.com/en-us/library/aa915056.aspx this is for windows mobile, because the original help is somehow unavailable, but i think its the same of desktop windows), which is stated to return "milliseconds until windows has started". And if you run windows for a while this value will reset, since it is wrapper by max value of DWORD/Cardinal. Well of course it is not very precise, actually it seems it is update by over 16 milliseconds.

    I havent used LclIntf.GetTickCount in Lazarus but I think it will have the same behavior as Winapi.

    if posible I tend to repeat certain procedure multiple times and check how much time is taken for that
    Yes i think this is very effective approach
    Last edited by Anton; 25-03-2015 at 07:06 AM.

  8. #8
    So this is the code i just write about *.exe file manipulation:
    Code:
    program TextureLoad;
    
    
    uses crt,SDL2,SDL2_image,SysUtils;
    
    
    type R=array[1..100] of pSDL_Renderer;
    	 T=array[1..100] of pSDL_Texture;
    
    
    var window:pSDL_Window; Render:R; Texture:T; i:byte;
    
    
    procedure Graphic_Initialisation;
    begin
    	clrscr;
    	if SDL_INIT(SDL_INIT_VIDEO)<0 then
    		begin
    			writeln('The graphic mode could not be initializated');
    			writeln('The application will now exit');
    			exit;
    		end
    	else
    		window:=SDL_CreateWindow('Texture Window',50,50,600,480,SDL_WINDOW_SHOWN);
    end;
    
    
    Procedure Load_Texture(ExePath:AnsiString);
    begin
    	Texture[1]:=IMG_LOADTEXTURE(Render[1],ExePath+'data\space_armada1.bmp');
    	Texture[2]:=IMG_LOADTEXTURE(Render[2],ExePath+'data\space_armada2.bmp');
    	Texture[3]:=IMG_LOADTEXTURE(Rrender[3],ExePath+'data\space_armada3.bmp');
    end;
    
    
    
    
    Procedure ComposerFrame;
    var Path:AnsiString;
    begin
    	Path:=ExtractPathFile('Texture.exe');
    	Load_Texture(Path);	
    end;
    			
    	
    	
    procedure Graphic_Destruction;
    begin
    	SDL_DestroyWindow(window);
    	SDL_QUIT;
    end;
    
    
    Begin
    	Graphic_Initialisation;
    	SDL_Delay(2000);
    	ComposerFrame;
    	Graphic_Destruction;
    end.
    The error i recive is this: Incompatible type for arg no. 2: Got "AnsiString", expected "PChar"

  9. #9
    This is the code i write to manipulate the *.exe file path extractor:

    Code:
    program TextureLoad;
    
    
    uses crt,SDL2,SDL2_image,SysUtils;
    
    
    type R=array[1..100] of pSDL_Renderer;
    	 T=array[1..100] of pSDL_Texture;
    
    
    var window:pSDL_Window; Render:R; Texture:T; i:byte;
    
    
    procedure Graphic_Initialisation;
    begin
    	clrscr;
    	if SDL_INIT(SDL_INIT_VIDEO)<0 then
    		begin
    			writeln('The graphic mode could not be initializated');
    			writeln('The application will now exit');
    			exit;
    		end
    	else
    		window:=SDL_CreateWindow('Texture Window',50,50,600,480,SDL_WINDOW_SHOWN);
    end;
    
    
    Procedure Load_Texture(ExePath:AnsiString);
    begin
    	T[1]:=IMG_LOADTEXTURE(R[1],ExePath+'data\space_armada1.bmp');
    	T[2]:=IMG_LOADTEXTURE(R[2],ExePath+'data\space_armada2.bmp');
    	T[3]:=IMG_LOADTEXTURE(R[3],ExePath+'data\space_armada3.bmp');
    end;
    
    
    
    
    Procedure ComposerFrame;
    var Path:AnsiString;
    begin
    	Path:=ExtractPathFile('Texture.exe');
    	Load_Texture(Path);	
    end;
    			
    	
    	
    procedure Graphic_Destruction;
    begin
    	SDL_DestroyWindow(window);
    	SDL_QUIT;
    end;
    
    
    Begin
    	Graphic_Initialisation;
    	SDL_Delay(2000);
    	ComposerFrame;
    	Graphic_Destruction;
    end.
    And the error is this: Arg no 2: AnsiString found but expected PChar.
    How do i solve it? Is there some kind of function that convert a AnsiString to a PChar? Or something like this?

  10. #10
    This is the code i just write to handle the files. The error i recive is that the path variable gets an AnsiString and the parameter for the IMG_LoadTexture is a pChar. How do i convert them?


    Code:
    program grafica;
    
    
    uses SysUtils,crt,SDL2,SDL2_image;
    
    
    type Textures=array[1..100] of pSDL_Texture;
    
    
    var Window:pSDL_Window; var Tex:Textures; Ren:pSDL_Renderer;
    
    
    procedure Graphic_Initialisation(var Window:pSDL_Window);
    begin
    	if SDL_INIT(SDL_INIT_VIDEO)<0 then
    		writeln('An error ocurred, the program will now quit')
    	else
    		begin
    			writeln('Graphic mode succesfully initialisated');
    			Window:=SDL_CreateWindow('Test',50,50,600,400,SDL_WINDOW_SHOWN);
    		end;
    end;
    
    
    procedure Texture_Loading;
    var path:pChar;
    begin
    	Ren:=SDL_CreateRenderer(window,-1,0);
    	path:=ExtractFilePath('grafica.exe');
    	Tex[1]:=IMG_LoadTexture(Ren,path+'\monster.bmp');
    	Tex[2]:=IMG_LoadTexture(Ren,path+'\monster1.bmp');;
    end;
    
    
    procedure Graphic_Composer;
    var i:byte;
    begin
    	Texture_Loading;
    	for i:=1 to 100 do
    		begin
    			if (i mod 2)=1 then
    				begin
    					SDL_RenderCopy(Ren,Tex[1],nil,nil);
    					SDL_RenderPresent(Ren);
    					SDL_DELAY(50);
    				end
    			else
    				begin
    					SDL_RenderCopy(Ren,Tex[2],nil,nil);
    					SDL_RenderPresent(Ren);
    					SDL_Delay(50);
    				end;
    		end;
    end;
    
    
    procedure Graphic_Destroy;
    var i:byte;
    begin
    	for i:=1 to 100 do	
    		SDL_DestroyTexture(Tex[i]);
    	SDL_DestroyRenderer(Ren);
    	SDL_DestroyWindow(Window);
    	SDL_QUIT;
    end;
    
    
    
    
    begin
        clrscr;
    	Graphic_Initialisation(Window);
    	Graphic_Composer;
    	Graphic_Destroy;
    end.

Page 2 of 3 FirstFirst 123 LastLast

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
  •