hedgewars/hwLibrary.pas
author unc0rr
Sun, 02 Dec 2012 01:25:11 +0400
changeset 8178 8bd087478b48
parent 7576 65d29988fd3d
child 9080 9b42757d7e71
permissions -rw-r--r--
Fix QSettings problems: - Reopen file in ReadOnly mode if it was open in ReadWrite mode and is being read. This is needed for stupid QSettings which opens file in ReadWrite mode just to call readAll() on it. - Implement setSize(0)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4930
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     1
(*
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6035
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
4930
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     4
 *
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     8
 *
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    12
 * GNU General Public License for more details.
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    13
 *
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    14
 * You should have received a copy of the GNU General Public License
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    15
 * along with this program; if not, write to the Free Software
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
5d59bb58c365 fix issue 185 :|
koda
parents: 4929
diff changeset
    17
 *)
2698
90585aba87ad objc/pascal finally working
koda
parents:
diff changeset
    18
6033
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    19
{$INCLUDE "options.inc"}
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    20
7048
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    21
(*
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    22
 * When engine is compiled as library this unit will export functions
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    23
 * as C declarations for convenient library usage in your application
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    24
 * and language of choice.
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    25
 *
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    26
 * See also: C declarations on Wikipedia
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    27
 *           http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    28
 *)
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    29
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    30
Library hwLibrary;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    31
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    32
uses hwengine, uTypes, uConsts, uVariables, uSound, uCommands, uUtils,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    33
     uLocale{$IFDEF ANDROID}, jni{$ENDIF};
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    34
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    35
{$INCLUDE "config.inc"}
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    36
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    37
// retrieve protocol information
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    38
procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    39
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    40
    netProto^:= cNetProtoVersion;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    41
    versionStr^:= cVersionString;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    42
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    43
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    44
// equivalent to esc+y; when closeFrontend = true the game exits after memory cleanup
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    45
procedure HW_terminate(closeFrontend: boolean); cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    46
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    47
    closeFrontend:= closeFrontend; // avoid hint
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    48
    ParseCommand('forcequit', true);
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    49
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    50
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    51
function HW_getWeaponNameByIndex(whichone: LongInt): PChar; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    52
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    53
    HW_getWeaponNameByIndex:= (str2pchar(trammo[Ammoz[TAmmoType(whichone+1)].NameId]));
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    54
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    55
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    56
(*function HW_getWeaponCaptionByIndex(whichone: LongInt): PChar; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    57
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    58
    HW_getWeaponCaptionByIndex:= (str2pchar(trammoc[Ammoz[TAmmoType(whichone+1)].NameId]));
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    59
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    60
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    61
function HW_getWeaponDescriptionByIndex(whichone: LongInt): PChar; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    62
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    63
    HW_getWeaponDescriptionByIndex:= (str2pchar(trammod[Ammoz[TAmmoType(whichone+1)].NameId]));
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    64
end;*)
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    65
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    66
function HW_getNumberOfWeapons: LongInt; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    67
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    68
    HW_getNumberOfWeapons:= ord(high(TAmmoType));
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    69
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    70
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    71
function HW_getMaxNumberOfHogs: LongInt; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    72
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    73
    HW_getMaxNumberOfHogs:= cMaxHHIndex + 1;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    74
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    75
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    76
function HW_getMaxNumberOfTeams: LongInt; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    77
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    78
    HW_getMaxNumberOfTeams:= cMaxTeams;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    79
end;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    80
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    81
procedure HW_memoryWarningCallback; cdecl; export;
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    82
begin
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    83
    ReleaseSound(false);
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
    84
end;
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    85
6027
302408e45052 code working on ios now
koda
parents: 6025
diff changeset
    86
{$IFDEF ANDROID}
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    87
function JNI_HW_versionInfoNet(env: PJNIEnv; obj: JObject):JInt;cdecl;
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    88
begin
6033
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    89
    env:= env; // avoid hint
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    90
    obj:= obj; // avoid hint
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    91
    JNI_HW_versionInfoNet:= cNetProtoVersion;
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    92
end;
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    93
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    94
function JNI_HW_versionInfoVersion(env: PJNIEnv; obj: JObject):JString; cdecl;
6033
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    95
var envderef : JNIEnv;
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
    96
begin
6033
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    97
    obj:= obj; // avoid hint
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    98
    envderef:= @env;
6bcc36225162 fix compiling for android, strip out all delphi code, objfpc ftw
koda
parents: 6027
diff changeset
    99
    JNI_HW_versionInfoVersion := envderef^.NewStringUTF(env, PChar(cVersionString));
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   100
end;
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   101
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7500
diff changeset
   102
procedure JNI_HW_GenLandPreview(env: PJNIEnv; c: JClass; port: JInt); cdecl;
7500
6253cae96f21 engine: Added JNI-compatible function to start map generation
Medo <smaxein@googlemail.com>
parents: 7083
diff changeset
   103
begin
6253cae96f21 engine: Added JNI-compatible function to start map generation
Medo <smaxein@googlemail.com>
parents: 7083
diff changeset
   104
	GenLandPreview(port);
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7500
diff changeset
   105
end;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7500
diff changeset
   106
6025
cac1d5601d7c reviewed the build system and parts of the previous merge, performed some code cleanup
koda
parents: 5452
diff changeset
   107
exports
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   108
    JNI_HW_versionInfoNet name Java_Prefix+'HWversionInfoNetProto', 
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   109
    JNI_HW_versionInfoVersion name Java_Prefix+'HWversionInfoVersion', 
7500
6253cae96f21 engine: Added JNI-compatible function to start map generation
Medo <smaxein@googlemail.com>
parents: 7083
diff changeset
   110
    JNI_HW_GenLandPreview name Java_Prefix + 'HWGenLandPreview',
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   111
    HW_getNumberOfweapons name Java_Prefix + 'HWgetNumberOfWeapons',
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   112
    HW_getMaxNumberOfHogs name Java_Prefix + 'HWgetMaxNumberOfHogs',
6035
bdd0528ee8a6 Close a game without leaking memory. It should be noted that sending an SDL Quit event leaks memory
Xeli
parents: 6033
diff changeset
   113
    HW_getMaxNumberOfTeams name Java_Prefix + 'HWgetMaxNumberOfTeams',
7083
5339aba29571 unbreak android build
Xeli
parents: 7048
diff changeset
   114
    Game;
7048
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   115
{$ELSE}
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   116
exports
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   117
    Game,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   118
    GenLandPreview,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   119
    LoadLocaleWrapper,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   120
    HW_versionInfo,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   121
    HW_terminate,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   122
    HW_getNumberOfWeapons,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   123
    HW_getMaxNumberOfHogs,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   124
    HW_getMaxNumberOfTeams,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   125
    HW_getWeaponNameByIndex,
0a4c88935902 the ios port runs again, although with a few things to sort out
koda
parents: 6700
diff changeset
   126
    HW_memoryWarningCallback;
5452
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   127
{$ENDIF}
3edc3e3b8cdc Created callbacks to give the frontend information of maxteams/hogs
Xeli
parents: 5166
diff changeset
   128
4187
adb144a907aa remove last warnings from xcodeproj
koda
parents: 3464
diff changeset
   129
begin
2698
90585aba87ad objc/pascal finally working
koda
parents:
diff changeset
   130
end.