Skip to content

Commit 3b62b97

Browse files
committed
Initial commit of the Package folder as a separate repository
To publish on GitHub separately from the master project folder (also to remove any potentially embarrassing commits as this is my first public open-source project 💧^^)
0 parents  commit 3b62b97

File tree

206 files changed

+16579
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+16579
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# OctopusKit Coding Conventions & Design Decisions
2+
3+
[Developer Diary](#developer-diary)
4+
[Comments Key](#comments-key)
5+
6+
- Git workflow: [http://nvie.com/posts/a-successful-git-branching-model/](http://nvie.com/posts/a-successful-git-branching-model/)
7+
8+
- OctopusKit types are prefixed with the word "Octopus" instead of "OK" because I liked it that way, and it saved me from a lot of refactoring when I had to change the name of the engine a few times.
9+
10+
- Classes are marked `final` where possible to improve performance. If you need to subclass them in a specific project, you could create a copy of the class (or entire engine source) and modify it to suit your project. See: [Increasing Performance by Reducing Dynamic Dispatch](https://developer.apple.com/swift/blog/?id=27)
11+
12+
- When checking a list of conditions in a single `if` or `guard`, check the condition that is the most likely to change each time, without which the operation will not continue, and the conditions that will most likely pass should be checked last, so that you save processing time by exiting early in the checklist instead of later.
13+
> In some cases however, it may be best to check the most important condition first. :)
14+
15+
- There are almost no `private` properties and methods in the OctopusKit API, so that you can observe almost everything at runtime, or customize in subclasses. Some may be read-only, however.
16+
17+
- Sometimes a type may have both type methods and instance methods for the same operations, like the `CGFloat+OctopusKit` extension with `distance(between:and:)` and `distance(to:)?` It may usually be more natural to write `distance = CGPoint.distance(between: a, and: b)` than `distance = a.distance(to: b)`, but it wouldn't do to make that method available only on the type and not on instances, so OK provides both. However, to reduce duplication of code, the instance methods are the "primary" code (to improve performance by reducing extra calls, because calling these methods on an instance may be more "idiomatic") and the type methods call the instance versions.
18+
19+
- `for each x in y` is cleaner and self-explanatory compared to `y.forEach { x in ... }` or `$0.z`
20+
21+
- In subclasses, try to prefix properties with `super.` or `self.` if there might be any ambiguity at the use site about where the property is defined.
22+
> TODO: example
23+
24+
- Say "player" instead of "user" whenever referring to the person playing the game. (^ ^)
25+
26+
## Developer Diary
27+
28+
- Trying to implement Scene Editor support for components via `@GKInspectable` seems like a waste of effort, as the editor does not show inspectable properties from a component's superclass. 2018-04-18
29+
30+
## Comments Key
31+
32+
- ℹ️ / DESIGN: A design decision or note.
33+
- ⚠️ A warning about potential undesirable behavior, or a previous undesirable situation that was learned and avoided or fixed.
34+
- 💬 General commentary/observations.
35+
- PERFORMANCE: Related to speed/efficiency/optimization.
36+
37+
----
38+
39+
OctopusKit © 2018 InvadingOctopus.com, github.com/invadingoctopus/octopuskit
40+
[Apache License 2.0][license]
41+
42+
[license]: https://www.apache.org/licenses/LICENSE-2.0.html
43+

Documentation/TODO & Roadmap.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# OctopusKit Roadmap
2+
3+
> If you'd like to help with the development of the OK project, these are some of the areas that need to be implemented.
4+
5+
1. [Major Missing Features](#major-missing-features)
6+
2. [To Do](#to-do)
7+
3. [To Decide](#to-decide)
8+
9+
## Major Missing Features
10+
11+
*More-or-less in order of priority/necessity:*
12+
13+
- Full macOS and tvOS support (currently in a preliminary state as of 2018-06-08.)
14+
- Components for mouse, keyboard, gamepad/joystick and Siri Remote input.
15+
- Asset/resource loading system.
16+
- Saving and loading game/scene/entity/component states via `Codable`.
17+
- Support for describing scenes/entities/components in HTML/XML/JSON or a similar format.
18+
- Networking components.
19+
- SceneKit support in 2D scenes, and 3D components.
20+
- Custom Scene Editor & Live Previewer?
21+
22+
## To Do
23+
24+
- Tests.
25+
- Improve coding conventions.
26+
- Write tutorials for common tasks.
27+
- Clarify `super` chaining where applicable – when an overridden method in a subclass *needs* to call the superclass method for the functionality to work correctly – and enforce it when it becomes possible through language support in a future version of Swift.
28+
- Eliminate the possibility of a `SKNode.physicsBody` being added to a scene more than once.
29+
- Internationalization/Localization
30+
- Implement configurable Xcode templates (single files with multiple variations based on options during file creation, e.g. single-state scenes vs. multi-state scenes.)
31+
- Add `Codable` support for components and their `init?(coder aDecoder: NSCoder)` where applicable.
32+
- GitHub Wiki?
33+
34+
### Performance Optimizations
35+
36+
- Replace `Array` with `ContiguousArray` where applicable.
37+
38+
## To Decide
39+
40+
- Shorten the prefix for engine types from "Octopus" to "OK"?
41+
- Use variadic parameters (`...`) instead of arrays in certain places, like `GKEntity.addComponent(_:)`?
42+
- Change `public` access to `open` or `internal`?
43+
- Write standalone documentation for every API unit? (Currently, source comments are the primary API documentation.)
44+
- Write documentation and tutorials for absolute beginners? i.e. people who have no experience with Xcode or Swift?
45+
46+
----
47+
48+
OctopusKit © 2018 InvadingOctopus.com, github.com/invadingoctopus/octopuskit
49+
[Apache License 2.0][license]
50+
51+
[license]: https://www.apache.org/licenses/LICENSE-2.0.html
52+
53+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# OctopusKit Tips & Troubleshooting
2+
3+
1. [Common Mistakes](#common-mistakes)
4+
2. [Best Practices](#best-practices)
5+
3. [Tips & Tricks](#tips-&-tricks)
6+
4. [Pitfalls & Gotchas](#pitfalls-&-gotchas)
7+
5. [Conditional Compilation Flags & Debugging Aids](#conditional-compilation-flags-&-debugging-aids)
8+
9+
## Common Mistakes
10+
11+
#### Components not having any effect?
12+
- If the component has an `update(deltaTime:)` method, make sure it's registered with a Component System, or is manually updated during the scene's `update(_:)` method, and *is only updated* ***once!*** [TODO: make this automatic]
13+
14+
- Does the entity have all the components that the non-functioning component depends on? A component's dependencies must be added to the entity before the component that depends on them. [TODO: make this automatic]
15+
16+
- Check the log.
17+
18+
#### Components having *too* much effect?
19+
- Make sure that a component is updated (if applicable) only once per frame.
20+
21+
- Also make sure that a component *system* is added to a scene only once!
22+
23+
#### Gesture recognizer components not working?
24+
- Check their properties for the minimum and maximum number of touches.
25+
26+
#### Scene, subscene or node not receiving input events?
27+
- Check its `isUserInteractionEnabled` property.
28+
29+
## Best Practices
30+
31+
- Remember to search the entire source code for `BUG:`, `APPLEBUG:`, `FIXME:` etc. comments for any outstanding bugs and their temporary workarounds, if any.
32+
33+
- In most cases, try to access the object hierarchy from the "bottom up" instead of "top down."
34+
35+
> TODO: Example
36+
37+
## Tips & Tricks
38+
39+
- You can have multiple "games" within a single project, by using multiple `OctopusGameController`s (each with its own set of `OctopusGameState`s and associated scenes, etc.) and programmatically choosing between them in `OctopusAppDelegate.configureOctopusEngine()`.
40+
41+
- TODO: Tip for sharing "global" data via `RelayComponent`s.
42+
43+
## Pitfalls & Gotchas
44+
45+
- Many methods MUST be overridden in a subclass and/or chained to the superclass implementation, by calling `super.method()`. Some methods should call `super` at different points (i.e. beginning or end) in the subclass' implementation. Unfortunately, there is no language-level support for enforcing that, so your best bet is to read the source and comments of the method you're overriding.
46+
> 💡 When in doubt, always call `super`, and call it at the top of your overriding method. [TODO: make this chaining automatic/enforced when/if Swift supports it]
47+
48+
- Components should try to perform their logic only during the `didAdd(...)`, `willRemove(...)`, and `update(deltaTime:)` methods. If a component's behavior must be modified outside of those methods, use flags that are then acted upon in the component's update method.
49+
This ensures that a component does not affect anything outside of a frame update and can be reliably paused/unpaused.
50+
> Note that this does not mean that a component should not _define_ any other methods at all.
51+
> TODO: Example
52+
53+
- Components that respond to asynchronous events, such as a component that moves a node based on input from a gesture recognizer, like `PanControlledRepositioningComponent`, or networking components, MUST perform their function inside their `update(deltaTime:)` method, and just use the event-handling action method to mark a flag to denote that an event was received.
54+
This prevents the component from being active outside the frame-update cycle, or when it's [temporarily] removed from the entity or the scene's systems.
55+
56+
- A SpriteKit scene processes touch and other input events **outside** of its `update(_:)` method; when those event handlers update input-processing components, those components will (should) only be able to act on the input data during the scene's `update(_:)` method.
57+
58+
- OctopusKit components may sometimes cause some "friction" against the SpriteKit API.
59+
e.g.: when adding a `SpriteKitComponent` and a `PhysicsComponent` to an entity; the SpriteKit node may have its own `physicsBody` and the `PhysicsComponent` may have a different `physicsBody`.
60+
- As a general rule, adding a component to an entity assumes that the component adds its encapsulated functionality to that entity, replacing any identical functionality that already exists.
61+
62+
> e.g.: If you add a "blank" component, e.g. a `PhysicsComponent` with a `nil` `physicsBody`, then the component attempts to "adopt" any existing properties of the underlying SpriteKit object.
63+
In this example, the blank `PhysicsComponent` will set its property to the `physicsBody`, if any, of the `SpriteKitComponent` node. After that, other components should access the node's physics properties through the `PhysicsComponent` instead of the node's `physicsBody` property.
64+
65+
- Entities and components may not always be the answer to everything. *Sometimes* good old classes and structs may be the better solution. (^ - ^")
66+
67+
- An entity can/should only have one component of a specific type (not counting generic variants.)
68+
If an entity needs multiple components of the same type but with different parameters, consider using a "master" component that holds a collection of regular classes/struct.
69+
> e.g.: a *ShipEntity* with a *WeaponsSystemComponent* that holds an array of *Gun* classes/structs, to represent multiple guns where each gun is mounted on a different side of the ship.
70+
71+
## Conditional Compilation Flags & Debugging Aids
72+
73+
> TODO: Instructions on where to enter these in Xcode
74+
75+
* `LOGINPUT` - Logs all input events and related information.
76+
77+
----
78+
79+
OctopusKit © 2018 InvadingOctopus.com, github.com/invadingoctopus/octopuskit
80+
[Apache License 2.0][license]
81+
82+
[license]: https://www.apache.org/licenses/LICENSE-2.0.html

0 commit comments

Comments
 (0)