Skip to content

Commit

Permalink
New event system
Browse files Browse the repository at this point in the history
  • Loading branch information
serp256 committed Mar 15, 2012
1 parent da70d5d commit c031188
Show file tree
Hide file tree
Showing 37 changed files with 1,908 additions and 2,319 deletions.
4 changes: 1 addition & 3 deletions config.linux
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,6 @@
export PLATFORM = SDL export PLATFORM = SDL
export OS = linux export OS = linux
OCAMLDIR = /usr/local/ export OCAMLFIND = ocamlfind
export OCAMLFIND = ocamlfind
OCAMLBINDIR = $(OCAMLDIR)/bin/
export OCAMLOPT = $(OCAMLFIND) ocamlopt export OCAMLOPT = $(OCAMLFIND) ocamlopt
export OCAMLC = $(OCAMLFIND) ocamlc export OCAMLC = $(OCAMLFIND) ocamlc
export OCAMLMKLIB = ocamlmklib export OCAMLMKLIB = ocamlmklib
Expand Down
60 changes: 17 additions & 43 deletions src/Atlas.ml
Original file line number Original file line Diff line number Diff line change
@@ -1,38 +1,9 @@
open LightCommon; open LightCommon;

type atlas; type atlas;
external atlas_init: unit -> atlas = "ml_atlas_init"; external atlas_init: unit -> atlas = "ml_atlas_init";
external atlas_clear_data: atlas -> unit = "ml_atlas_clear" "noalloc"; external atlas_clear_data: atlas -> unit = "ml_atlas_clear" "noalloc";


module type S = sig

module D : DisplayObjectT.S;

class c: [ Texture.c ] ->
object
inherit D.c;
method texture: Texture.c;
method filters: list Filters.t;
method setFilters: list Filters.t -> unit;
method private render': ?alpha:float -> ~transform:bool -> option Rectangle.t -> unit;
method boundsInSpace: !'space. option (<asDisplayObject: D.c; .. > as 'space) -> Rectangle.t;
method addChild: ?index:int -> AtlasNode.t -> unit;
method children: Enum.t AtlasNode.t;
method clearChildren: unit -> unit;
method getChildAt: int -> AtlasNode.t;
method numChildren: int;
method updateChild: int -> AtlasNode.t -> unit;
method removeChild: int -> unit;
method setChildIndex: int -> int -> unit;
end;


value create: Texture.c -> c;

end;

module Make(D:DisplayObjectT.S) = struct
module D = D;

module Node = AtlasNode; module Node = AtlasNode;


external atlas_render: atlas -> Matrix.t -> Render.prg -> textureID -> bool -> float -> option (DynArray.t Node.t) -> unit = "ml_atlas_render_byte" "ml_atlas_render" "noalloc"; external atlas_render: atlas -> Matrix.t -> Render.prg -> textureID -> bool -> float -> option (DynArray.t Node.t) -> unit = "ml_atlas_render_byte" "ml_atlas_render" "noalloc";
Expand All @@ -46,11 +17,9 @@ module Make(D:DisplayObjectT.S) = struct
g_params: Filters.glow g_params: Filters.glow
}; };


(* сюда припиздячить glow еще нахуй *) class _c texture =
class c texture =
(* нужно сделать фсю gl хуйню *)
object(self) object(self)
inherit D.c as super; inherit DisplayObject.c as super;


value atlas = atlas_init (); value atlas = atlas_init ();


Expand All @@ -74,26 +43,26 @@ module Make(D:DisplayObjectT.S) = struct
| Some index -> | Some index ->
try try
DynArray.insert children index child DynArray.insert children index child
with [ DynArray.Invalid_arg _ -> raise D.Invalid_index ] with [ DynArray.Invalid_arg _ -> raise DisplayObject.Invalid_index ]
]; ];
Node.bounds child |> ignore; (* force calc bounds *) Node.bounds child |> ignore; (* force calc bounds *)
self#boundsChanged(); self#boundsChanged();
); );


method getChildAt idx = try DynArray.get children idx with [ DynArray.Invalid_arg _ -> raise D.Invalid_index ]; method getChildAt idx = try DynArray.get children idx with [ DynArray.Invalid_arg _ -> raise DisplayObject.Invalid_index ];


method removeChild idx = method removeChild idx =
try try
DynArray.delete children idx; DynArray.delete children idx;
self#boundsChanged(); self#boundsChanged();
with [ DynArray.Invalid_arg _ -> raise D.Invalid_index ]; with [ DynArray.Invalid_arg _ -> raise DisplayObject.Invalid_index ];


method updateChild idx child = method updateChild idx child =
( (
assert(child.Node.texture = texture); assert(child.Node.texture = texture);
try try
DynArray.set children idx child; DynArray.set children idx child;
with [ DynArray.Invalid_arg _ -> raise D.Invalid_index ]; with [ DynArray.Invalid_arg _ -> raise DisplayObject.Invalid_index ];
Node.bounds child |> ignore; (* force calc bounds *) Node.bounds child |> ignore; (* force calc bounds *)
self#boundsChanged(); self#boundsChanged();
); );
Expand All @@ -119,10 +88,10 @@ module Make(D:DisplayObjectT.S) = struct
DynArray.delete children idx; DynArray.delete children idx;
DynArray.insert children nidx child; DynArray.insert children nidx child;
) )
with [ DynArray.Invalid_arg _ -> raise D.Invalid_index ]; with [ DynArray.Invalid_arg _ -> raise DisplayObject.Invalid_index ];
self#childrenDirty(); self#childrenDirty();
) )
else raise D.Invalid_index; else raise DisplayObject.Invalid_index;


value mutable glowFilter = None; value mutable glowFilter = None;


Expand Down Expand Up @@ -227,7 +196,7 @@ module Make(D:DisplayObjectT.S) = struct
filters := fltrs; filters := fltrs;
); );


method boundsInSpace: !'space. (option (<asDisplayObject: D.c; .. > as 'space)) -> Rectangle.t = fun targetCoordinateSpace -> method boundsInSpace: !'space. (option (<asDisplayObject: DisplayObject.c; .. > as 'space)) -> Rectangle.t = fun targetCoordinateSpace ->
match DynArray.length children with match DynArray.length children with
[ 0 -> Rectangle.empty [ 0 -> Rectangle.empty
| _ -> | _ ->
Expand Down Expand Up @@ -306,6 +275,11 @@ module Make(D:DisplayObjectT.S) = struct


end; end;


value create = new c; class c texture =
object(self)
inherit _c texture;
method ccast: [= `Atlas of c ] = `Atlas (self :> c);
end;

value create = new c;


end;
51 changes: 25 additions & 26 deletions src/Atlas.mli
Original file line number Original file line Diff line number Diff line change
@@ -1,30 +1,29 @@




module type S = sig


module D : DisplayObjectT.S;


class c: [ Texture.c ] -> class _c: [ Texture.c ] ->
object object
inherit D.c; inherit DisplayObject.c;
method texture: Texture.c; method texture: Texture.c;
method filters: list Filters.t; method filters: list Filters.t;
method setFilters: list Filters.t -> unit; method setFilters: list Filters.t -> unit;
method private render': ?alpha:float -> ~transform:bool -> option Rectangle.t -> unit; method private render': ?alpha:float -> ~transform:bool -> option Rectangle.t -> unit;
method boundsInSpace: !'space. option (<asDisplayObject: D.c; .. > as 'space) -> Rectangle.t; method boundsInSpace: !'space. option (<asDisplayObject: DisplayObject.c; .. > as 'space) -> Rectangle.t;
method addChild: ?index:int -> AtlasNode.t -> unit; method addChild: ?index:int -> AtlasNode.t -> unit;
method children: Enum.t AtlasNode.t; method children: Enum.t AtlasNode.t;
method clearChildren: unit -> unit; method clearChildren: unit -> unit;
method getChildAt: int -> AtlasNode.t; method getChildAt: int -> AtlasNode.t;
method numChildren: int; method numChildren: int;
method updateChild: int -> AtlasNode.t -> unit; method updateChild: int -> AtlasNode.t -> unit;
method removeChild: int -> unit; method removeChild: int -> unit;
method setChildIndex: int -> int -> unit; method setChildIndex: int -> int -> unit;
end; end;



class c: [ Texture.c ] ->
value create: Texture.c -> c; object

inherit _c;
end; method ccast: [= `Atlas of c ];

end;
module Make(D:DisplayObjectT.S) : S with module D = D;
value create: Texture.c -> c;
Loading

0 comments on commit c031188

Please sign in to comment.