[Tool/Web/Other] System-oriented approach (SOA) for Pawn
#1

System-oriented approach
Short description:
This approach allows you to divide your gamemode into parts.
The structure of SOA:
  • Including main libraries
  • Including the core
The structure of the core:
  • Including classes (file "classes.pwn" in "gamemode" directory is a list of systems and them params)
  • Including some constants (colors or something else)
  • Including config (you can store some data here, mysql configuration for example)
  • Including global ("global" is global functions with no class, macros or variables maybe)
    -
  • Including variables of systems (classes) required it.
  • Including macros of systems (classes) required it.
  • Including functions of systems (classes) required it.
  • Including events of systems (classes) requires it.
That's all.

The structure of some system (some class). Each system may include vars, macros, functions and events and have respectively four or fewer files. Further, the system if it's required may have objects. For example, if you have created a system "players", the object of this system would be an "player".

How to create the system?

1. Discribe the class in this way (file classes.pwn):

PHP код:
#define players. a_ // Allocate symbol for the system
#define a_@ "players" // Set the name of the system
#define a_@@ 0 // Set the number of the system
...
#define gamemode. b_
#define b_@ "gamemode"
#define b_@@ 1
#define vehicles. c_
#define c_@ "vehicles"
#define c_@@ 2
... 
2. Create the directory system in gamemode directory.

Variables (file "system.variables.pwn")

If you want to create objects of system, you have to write this:
PHP код:
/*!
    - Objects Static
*/
#define Objects. Objects_
#define Object. Object_
#define CLASS_NAME Objects
#define CLASS_DATA Object
en(Data)
{
    
i.SomeIntVar;
    
f.SomeFloatVar;
    
i.SomeArrayOfVars[TheSizeOfTheArray];
}
nw[CountOfObjects]{Data};
#undef    Objects
#undef    Object
#define    Objects[%0].        Objects[%0][Object_@
#define    Object            Objects[object]
#undef    CLASS_NAME
#undef    CLASS_DATA 
Or if you want to create just a variable of the system:

PHP код:
new this.VarNamethis.VarName2
Macros (file "system.macro.pwn")

Then again if you want to create objects of system, you have to create some necessary macros:

PHP код:
#define object                objectid
#define objectid.%0(%1)        objects.%0(_:object,%1) 
Hence we see that object and objectid is the same.
You also can add your own macros for any aims.

Functions (file "system.functions.pwn")

Functions may be created by simple way.
Normal functions of system:

PHP код:
is.Name()
{
    
// stock and integer function
}
ip.Name1(param0param1, ...)
{
    
// public and integer function
}
in.Name2(param0param1, ...)
{
    
// normal integer function
}
fs.Name3(param0param1, ...)
{
    
// stock and float
}
bs.Name4()
{
    
// stock and bool

i - integer, b - bool, f - float
s - stock, n - normal, p - forward + public

Functions with objects (or methods):

PHP код:
is.SomeMethod(object)
{
    
// some actions over the object

Example:

PHP код:
// class "players"
is.Teleport(playerfloat:xfloat:yfloat:z)
{
    
Player.Pos.x// Player.Pos.X ~ Player.Pos[0] ~ Players[player].Pos[0] ~ Players[player][Player_Pos][0]
    
Player.Pos.y// Player.Pos.Y ~ Player.Pos[1] ~ Players[player].Pos[1] ~ Players[player][Player_Pos][1]
    
Player.Pos.z// Player.Pos.Z ~ Player.Pos[2] ~ Players[player].Pos[2] ~ Players[player][Player_Pos][2]
    
player.SetPos(); // <- is the method set position to player
}
is.SetPos(player)
{
    
SetPlayerPos(playerPlayer.Pos.XPlayer.Pos.YPlayer.Pos.Z);
}
is.GetPos(player)
{
    
GetPlayerPos(playerPlayer.Pos.XPlayer.Pos.YPlayer.Pos.Z);

How to call some function or method (if it's an object)?

PHP код:
// class "players"
is.Connect(player// it's event
{
    
// to call some method use:
    
player.SomeMethod(params); // player is the object
    // to call normal function use:
    
players.NormalFunctions(params); // players is the system
    // you also can write shortly
    
this.NormalFunctions(params); // If you locate in "players" system
    
thi.SomeMethod(params); // If you locate in "players" system and "player" is an object of this system.
    
one.SomeMethod(params); // the same

Events (file "system.events.pwn")

Events are divided into two types: for system, for object.
Examples:

PHP код:
// class "players"
cl.Connect(player// is the same as "OnPlayerConnect"
{
    
// cl - callback (public function without forward)
    // callback to the object
}
// class "gamemode"
cl.Init()
{
    
// callback to the system
}
// you also can make your own event
is.SomeEvent()
{
    
// do something

To call the callback you have to write this:

PHP код:
is.MoveToXYZ(playerfloat:xfloat:yfloat:z// simple method
{
    
player.@Move();
    
// or
    
players.@Move(player);
    
// "Move" is the function, "@Move" is the event!

How to use two objects in an function?
Example:

PHP код:
is.MoveToPlayer(playerplayer1)
{
    
players.GetPos(player1);
    
    
Player.Pos.Players[player1].Pos.X;
    
Player.Pos.Players[player1].Pos.Y;
    
Player.Pos.Players[player1].Pos.Z;
    
    
player.SetPos(player);
}
// or
is.MoveToPlayer(playerplayer1)
{
    
players.GetPos(player1);
    
    for(
-> 3Player.Pos[i] = Players[player1].Pos[i];
    
    
player.SetPos(player);

So, it's all. Learn it, if you want.
If you have any questions, post them here! I try to answer each of them.
I'm probably very poorly explained...
Reply
#2

Nicee!
Reply
#3

just because you can fiddle with the oh-so-loose preprocessor doesn't mean you should! replacement specifiers alone isn't a perfect solution for what you plan to achieve. so many inconsistencies, syntax is just awful (not even close to the real approach), in short - i'm not a fan.
Reply
#4

Quote:
Originally Posted by Ada32
Посмотреть сообщение
just because you can fiddle with the oh-so-loose preprocessor doesn't mean you should! replacement specifiers alone isn't a perfect solution. so many inconsistencies, syntax is just awful (not even close to the real approach), in short - i'm not a fan.
I never said that I want to copy the OOP. This is absolutely wrong. And the syntax is what it is. Of course, it's not a Pawn syntax. And I just share my idea, nothing more.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)