clean up
This commit is contained in:
parent
55f0d4d9a8
commit
b2529956a2
76
main.odin
76
main.odin
@ -17,67 +17,27 @@ print_usage :: proc() {
|
||||
os.exit(1)
|
||||
}
|
||||
|
||||
//TODO: struct for ppm file
|
||||
|
||||
load_ppm :: proc() -> (data: []byte) {
|
||||
if len(os.args) > 3 || len(os.args) < 2 {
|
||||
print_usage()
|
||||
}
|
||||
filename := os.args[1]
|
||||
//fmt.printfln("filename: %s", filename)
|
||||
|
||||
if !strings.has_suffix(filename, ".ppm") {
|
||||
fmt.eprintfln("ERROR: File %s does not have a valid ppm extention (.ppm)", filename)
|
||||
os.exit(1)
|
||||
}
|
||||
|
||||
//now read file
|
||||
succ: bool
|
||||
data, succ = os.read_entire_file_from_filename(filename, context.temp_allocator)
|
||||
if !succ {
|
||||
fmt.eprintfln("ERROR: Failed to load file: %s ", filename)
|
||||
os.exit(1)
|
||||
}
|
||||
return data //don't like naked returns
|
||||
}
|
||||
|
||||
load_ppm_to_rect :: proc() -> (rect: SDL.Rect) {
|
||||
if len(os.args) > 3 || len(os.args) < 2 {
|
||||
print_usage()
|
||||
}
|
||||
filename := os.args[1]
|
||||
//fmt.printfln("filename: %s", filename)
|
||||
|
||||
if !strings.has_suffix(filename, ".ppm") {
|
||||
fmt.eprintfln("ERROR: File %s does not have a valid ppm extention (.ppm)", filename)
|
||||
os.exit(1)
|
||||
}
|
||||
|
||||
//now read file
|
||||
data, succ := os.read_entire_file_from_filename(filename, context.temp_allocator)
|
||||
if !succ {
|
||||
fmt.eprintfln("ERROR: Failed to load file: %s ", filename)
|
||||
os.exit(1)
|
||||
}
|
||||
|
||||
it := string(data)
|
||||
for line in strings.split_lines_iterator(&it) {
|
||||
switch line {
|
||||
case "#":
|
||||
continue
|
||||
//ignore comments
|
||||
case "P3":
|
||||
fmt.println("has P3")
|
||||
case "P6":
|
||||
fmt.println("has P6")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return {0, 0, 0, 0}
|
||||
}
|
||||
main :: proc() {
|
||||
//first check if the user has provided a ppm file
|
||||
load_ppm_to_rect()
|
||||
file := Ppm_file{}
|
||||
|
||||
if len(os.args) > 3 || len(os.args) < 2 {
|
||||
print_usage()
|
||||
}
|
||||
filename := os.args[1]
|
||||
success := load_ppm(&file, filename)
|
||||
|
||||
if !success {
|
||||
fmt.eprintfln("Could not load file %s", filename)
|
||||
os.exit(1)
|
||||
}
|
||||
ppm_parse(&file)
|
||||
|
||||
fmt.println(file.magic_num)
|
||||
fmt.println(file.width)
|
||||
fmt.println(file.height)
|
||||
|
||||
sdl_init_error := SDL.Init(SDL.INIT_VIDEO)
|
||||
assert(sdl_init_error == 0, SDL.GetErrorString())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user