Skip to content

Commit

Permalink
Uploaded the source code of Atom 0.5
Browse files Browse the repository at this point in the history
This is Atom-0.5-ALPHA. The first public version of Atom. I hope you like it.
  • Loading branch information
crazyRBLX11 committed Oct 29, 2024
1 parent 43daea3 commit 380c012
Show file tree
Hide file tree
Showing 16 changed files with 1,046 additions and 1 deletion.
2 changes: 2 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build
Do <b>NOT</b> build from this repository, due to limitations with putting scripts under ModuleScripts I've had to restructure the repository. If you build this repository and try to use it you'll only end up with errors. If you know how I could fix this please put a pull request or an issue ticket and I'll contact you via it. If you'd like to use Atom, please use a pre-built .rbxm under releases.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Atom Framework

An easy to implement Roblox framework.

## Introduction
The Atom Framework is an open-source framework used for crazyattaker1's games on Roblox.
The Atom Framework is easy to work with and encourages modular coding.
Documentation can be found in the documentation/ folder.

## Features
Atom was designed to do all the heavy work for multi module codebases. Some of the features Atom contains to assist you as a developer are:
* Services, Controllers and Components - Seperate server and client code by using specialized containers for each type and a special type for shared code called Components.
* Libraries - Packages from the Atom registry to include extra functionality that you can implement in your own modules.
* Out-of-the-box Networking - A custom developed network solution that doesn't rely on Roblox remotes.
* Automatic error handling - Allow Atom to automatically deal with errors or tell it what to do when an error occurs.
* Automatic Garbage Collection - Atom uses the Janitor module to clean up instances when they're no longer needed.
1 change: 1 addition & 0 deletions selene.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std = "roblox"
12 changes: 12 additions & 0 deletions src/Atom/Atom.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local RunService = game:GetService("RunService")

if RunService:IsServer() then
return require(script.AtomServer_OOP)
else
local AtomServer = script:FindFirstChild("AtomServer_OOP")
if AtomServer and RunService:IsRunning() then
AtomServer:Destroy()
end

return require(script.AtomClient_OOP)
end
213 changes: 213 additions & 0 deletions src/Atom/AtomModuleContents/AtomClient_OOP.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
--!strict
--!native
--[[
Rewrite of my 2019-2021 framework.
~31/10/2023 crazyattaker1
Tools Used in Atom Development: VSCode Insider Edition, Argon Code Sync.
]]

-- Initialize the Module Script table to allow external access
-- to the API and making a reference to where everything SHOULD be stored.
local AtomMain = {}
local AtomRoot = script.Parent.Parent

local started = false
local startComplete = false

-- Make Types for tables and arrays as they don't officially have types.
type tab = { [string] : string | boolean | Instance }
type array<typ> = { [number] : typ }

-- Set Important Directories
local Controllers = AtomRoot.Controllers
local Components = AtomRoot.Components
local Packages = AtomRoot:WaitForChild("Packages")

-- Overwrite Functions
--local ModuleLoader = require(Packages.ModuleLoader) -- Needed for custom require.
--[[local function require(Directory:Instance, ScriptName:string)
return ModuleLoader.new(Directory, ScriptName)
end ]]
local function wait(seconds:number)
return task.wait(seconds)
end
local function Wait(duration:number)
return task.wait(duration)
end
local function SubTick()
return tick() / 2
end

-- Load all the Packages into Memory.
--[[
local BSON = require(Packages, "BSON")
local GoodSignal = require(Packages, "GoodSignal")
local Janitor = require(Packages, "Janitor")
local PartCache = require(Packages, "PartCache")
local Promise = require(Packages, "Promise")
local Proto = require(Packages, "proto")
local ProfileService = require(Packages, "ProfileService")
local Sourceesque = require(Packages, "Sourceesque")
local Warp = require(Packages, "Warp") ]]

local GoodSignal = require(Packages.GoodSignal)
local Janitor = require(Packages.Janitor)
local Promise = require(Packages.Promise)
local Switch, case, default = unpack(require(Packages.Switch))

function serialize(Buffer: buffer, offset: number, DataType: string, Data)
local dataType = string.lower(DataType)

Switch(Data)({
case("number")(function()
buffer.writef64(Buffer, offset * math.random(1, 34), Data)
end),

case("string")(function()
if #Data <= 1024 then -- each character takes 1 byte
buffer.writestring(Buffer, 0, Data)
else
return warn("Data is too large for the buffer.")
end
end),

case("table")(function()
for i, v in ipairs(Data) do
serialize(Buffer, offset, DataType, v) -- recursively serialize each element in the table
end
end),

default()(function()
return warn("Unsupported Data Type.")
end),
})
end

-- Make references for Repositories.
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = AtomRoot.AtomRemotes

local onCompletedSignal = Instance.new("BindableEvent", Remotes.BindableEvents)
onCompletedSignal.Name = "onCompleted"
local ErrorSignal = GoodSignal.new()

-- DRY Signal Handler.
ErrorSignal:Connect(function(message)
error(message, 2)
end)

--[[
Internal clean function.
Run the function Clean()
This function can be used anywhere internally and should
be used like the following:
function YourFunction(YourFunctionsParmaters)
local YourFunctionsJanitor = Janitor.new()
-- Your Function's Code
YourFunctionsJanitor:Add(YourFunctionsInstance)
Clean(YourFunctionsJanitor)
end ]]

function Clean(WorkingJanitor)
WorkingJanitor:Cleanup()
print("Memory Usage: "..collectgarbage('count').."kb")
print("Memory Usage: "..collectgarbage('count') * 1024, "B")
return "Cleaned"
end

--[[
Initialize the framework.
Require the ModuleScript and run this function ONCE
to set up the framework for everything else.
This function is located in the customizable BootStrapper
parented under this ModuleScript and should be used like
the following:
local Origin = require(script.Parent)
Origin:Init()
]]
function AtomMain.Start()
if started then return Promise.reject("Atom has already started.") end
if _VERSION ~= "Luau" then ErrorSignal:Fire("Running on an External Lua Runtime.") return end

local StartTick = tick()
local StartSubTick = SubTick()

started = true

return Promise.new(function(resolve)
-- Create a Janitor to clean unneeded files post setup.
local InitJanitor = Janitor.new()

local controllerInitPromises = {}

for _, Controller in ipairs(Controllers:GetDescendants()) do
if Controller:IsA("ModuleScript") and Controller.Name:match("Controller$") then
table.insert(
controllerInitPromises,
Promise.new(function(r)
debug.setmemorycategory(Controller.Name)
local controllertouse = require(Controllers, Controller.Name)
controllertouse.new()
controllertouse:Init()
r()
end)
)
end
end

-- Cleaning up anything left from the Auto Installer.
print(Clean(InitJanitor))
resolve(Promise.all(controllerInitPromises))
end):andThen(function()
local controllersStartPromises = {}

for _, controller in ipairs(Controllers:GetDescendants()) do
if controller:IsA("ModuleScript") and controller.Name:match("Controller$") then
table.insert(
controllersStartPromises,
Promise.new(function(r)
debug.setmemorycategory(controller.Name)
local controllertouse = require(Controllers, controller.Name)
controllertouse.new()
controllertouse:Start()
r()
end)
)
end
end

startComplete = true
local EndTick = tick()
local EndSubTick = SubTick()
onCompletedSignal:Fire("Atom has started succesfully.")
local InitTick = tostring(EndTick - StartTick)
local InitSubTick = tostring(EndSubTick - StartSubTick)
print("Atom Started with a tick of "..InitTick.." and a sub tick of "..InitSubTick..".")
end)
end

--[[function AtomMain.GetController(ControllerName:string)
for i, v in ipairs(Controllers:GetDescendants()) do
if v:IsA("ModuleScript") and v.Name == ControllerName then
return require(Controllers, ControllerName)
else
continue
end
end
end ]]

local Core = script.Parent.Core.Client

return {
versiondetails = { major = 0, minor = 1, isrelease = false },
AtomRoot = AtomRoot,
Main = AtomMain
}
Loading

0 comments on commit 380c012

Please sign in to comment.