Commit 38afa531 authored by Tom Barbalet's avatar Tom Barbalet

More clean up

parent af0dec76
Pipeline #121639318 passed with stages
in 53 minutes and 29 seconds
/****************************************************************
client.c
=============================================================
Copyright 1996-2020 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software is a continuing work of Tom Barbalet, begun on
13 June 1996. No apes or cats were harmed in the writing of
this software.
****************************************************************/
#include "client.h"
#include <stdlib.h>
#include <time.h>
n_int hpv_exit, hpv_dt;
n_int hpv_x, hpv_y, hpv_f, hpv_i;
n_int hpv_r0, hpv_r1;
void loop_no_thread(noble_simulation * sim, noble_being * being_not, loop_fn bf_func, void * data)
{
n_int loop = 0;
while (loop < sim->count)
{
noble_being * output = &(sim->beings[loop]);
if (output != being_not)
{
bf_func(sim, output, data);
}
loop++;
}
}
typedef struct {
n_int signature, version_number;
n_string copyright, date;
} client_simulation_identifier;
typedef struct {
n_vect2 location;
n_int direction_facing, velocity, stored_energy, identification, state;
n_int genetics[4];
n_string name;
} client_being;
typedef struct {
n_vect2 genetics;
n_int date, time;
} client_land;
typedef struct {
client_land land;
client_simulation_identifier id;
client_being * beings;
n_int being_count;
n_int being_max;
n_uint being_selected_id;
} client_data;
static void client_from_file(client_data * data, n_file * file_json)
{
io_whitespace_json(file_json);
{
n_object * returned_object = object_file_to_tree(file_json);
if (returned_object)
{
n_string str_information = obj_contains(returned_object, "information", OBJECT_OBJECT);
n_string str_land = obj_contains(returned_object, "land", OBJECT_OBJECT);
n_string str_beings = obj_contains(returned_object, "beings", OBJECT_ARRAY);
n_int value = 0;
if (str_information)
{
n_object * information_obj = obj_get_object(str_information);
n_string potential = obj_contains(information_obj, "copyright", OBJECT_STRING);
if (potential)
{
data->id.copyright = potential;
}
potential = obj_contains(information_obj, "date", OBJECT_STRING);
if (potential)
{
data->id.date = potential;
}
if (obj_contains_number(information_obj, "signature", &value))
{
data->id.signature = value;
}
if (obj_contains_number(information_obj, "version_number", &value))
{
data->id.version_number = value;
}
}
if (str_land)
{
n_object * land_obj = obj_get_object(str_land);
(void)obj_contains_array_numbers(land_obj, "genetics", data->land.genetics.data, 2);
if (obj_contains_number(land_obj, "date", &value))
{
data->land.date = value;
}
if (obj_contains_number(land_obj, "time", &value))
{
data->land.time = value;
}
}
if (str_beings)
{
n_array * beings_array = obj_get_array(str_beings);
n_int being_count = obj_array_count(beings_array);
n_array * arr_second_follow = 0L;
if (being_count > data->being_max)
{
if (data->beings)
{
memory_free((void**)&data->beings);
}
data->beings = (client_being*) memory_new((n_uint)(sizeof(client_being) * (n_uint)being_count));
data->being_max = being_count;
}
if (beings_array)
{
being_count = 0;
while ((arr_second_follow = obj_array_next(beings_array, arr_second_follow)))
{
n_object * obj_being = obj_get_object(arr_second_follow->data);
client_being * being = &(data->beings[being_count++]);
if (obj_contains_number(obj_being, "state", &value))
{
being->state = value;
}
if (obj_contains_number(obj_being, "direction_facing", &value))
{
being->direction_facing = value;
}
if (obj_contains_number(obj_being, "velocity", &value))
{
being->velocity = value;
}
if (obj_contains_number(obj_being, "stored_energy", &value))
{
being->stored_energy = value;
}
if (obj_contains_number(obj_being, "identification", &value))
{
being->identification = value;
}
(void)obj_contains_array_numbers(obj_being, "location", being->location.data, 2);
(void)obj_contains_array_numbers(obj_being, "genetics", being->genetics, 4);
}
}
}
}
}
}
/****************************************************************
client.h
=============================================================
Copyright 1996-2020 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software is a continuing work of Tom Barbalet, begun on
13 June 1996. No apes or cats were harmed in the writing of
this software.
****************************************************************/
#ifndef NOBLEAPE_CLIENT_H
#define NOBLEAPE_CLIENT_H
#include "../noble/noble.h"
#define CHROMOSOMES 4
void transfer_parameters(void);
void transfer_sim_start(void);
n_file * transfer_out_json(void);
#ifdef NOBLE_APE_CLIENT
typedef n_uint n_genetics;
typedef struct {
n_int signature, version_number;
n_string copyright, date;
} noble_simulation_identifier;
typedef struct {
n_vect2 location;
n_int direction_facing, velocity, stored_energy, identification, state;
n_int genetics[4];
n_string name;
} noble_being;
typedef struct {
n_vect2 genetics;
n_int date, time;
} noble_land;
typedef struct {
noble_land land;
noble_simulation_identifier id;
noble_being * beings;
noble_being * select;
n_int count;
n_int max;
n_uint being_selected_id;
n_uint real_time;
} noble_simulation;
#ifdef BRAIN_ON
n_byte * being_brain(noble_being * value);
#endif
n_int being_energy(noble_being * value);
n_byte being_facing(noble_being * value);
n_genetics * being_genetics(noble_being * value);
void being_high_res(noble_being * value, n_vect2 * vector);
n_byte being_line_of_sight(noble_being * local, n_vect2 * location);
n_int being_location_x(noble_being * value);
n_int being_location_y(noble_being * value);
void being_space(noble_being * value, n_vect2 * vector);
n_byte being_speed(noble_being * value);
n_byte2 being_state(noble_being * value);
n_int being_female(noble_being * value);
n_int being_speaking(noble_being * value);
n_int command_save(void * ptr, n_string response, n_console_output output_function);
n_int command_open(void * ptr, n_string response, n_console_output output_function);
n_int command_script(void * ptr, n_string response, n_console_output output_function);
#ifdef BRAINCODE_ON
void command_populate_braincode(noble_simulation * local_sim, line_braincode function);
#endif
n_int command_stop(void * ptr, n_string response, n_console_output output_function);
typedef void (loop_fn)(noble_simulation * sim, noble_being * actual, void * data);
void loop_no_thread(noble_simulation * sim, noble_being * being_not, loop_fn bf_func, void * data);
void sim_close(void);
void * sim_init(KIND_OF_USE kind, n_uint randomise, n_uint offscreen_size, n_uint landbuffer_size);
void sim_cycle(void);
void sim_flood(void);
void sim_healthy_carrier(void);
void sim_realtime(n_uint time);
n_int sim_new(void);
n_int sim_new_run_condition(void);
void sim_view_options(n_int px, n_int py);
void sim_rotate(n_int integer_rotation_256);
void sim_move(n_int rel_vel, n_byte kind);
void sim_change_selected(n_byte forwards);
n_int sim_view_regular(n_int px, n_int py);
void sim_terrain(n_int sx);
noble_simulation * sim_sim(void);
#ifndef _WIN32
n_int sim_thread_console_quit(void);
void sim_thread_console(void);
#endif
#endif
#endif /* NOBLEAPE_CLIENT_H */
/****************************************************************
client_being.c
=============================================================
Copyright 1996-2020 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software is a continuing work of Tom Barbalet, begun on
13 June 1996. No apes or cats were harmed in the writing of
this software.
****************************************************************/
#include "client.h"
#ifdef BRAIN_ON
n_byte * being_brain(noble_being * value)
{
return 0L;
}
#endif
n_int being_female(noble_being * value)
{
return 0; /*TODO: genetics handling */
}
n_int being_speaking(noble_being * value)
{
return value->state; /* TODO: Add speaking constant check */
}
n_int being_energy(noble_being * value)
{
return value->stored_energy;
}
n_byte being_facing(noble_being * value)
{
return (n_byte)value->direction_facing;
}
n_genetics * being_genetics(noble_being * value)
{
return (n_genetics *)value->genetics;
}
void being_high_res(noble_being * value, n_vect2 * vector)
{
}
n_byte being_line_of_sight(noble_being * local, n_vect2 * location)
{
return 0;
}
n_int being_location_x(noble_being * value)
{
return value->location.x;
}
n_int being_location_y(noble_being * value)
{
return value->location.y;
}
void being_space(noble_being * value, n_vect2 * vector)
{
vector->x = value->location.x;
vector->y = value->location.y;
}
n_byte being_speed(noble_being * value)
{
return (n_byte)value->velocity;
}
n_byte2 being_state(noble_being * value)
{
return (n_byte2)value->state;
}
/****************************************************************
client_sim.c
=============================================================
Copyright 1996-2020 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software is a continuing work of Tom Barbalet, begun on
13 June 1996. No apes or cats were harmed in the writing of
this software.
****************************************************************/
#define CONSOLE_REQUIRED
#define CONSOLE_ONLY
#include "client.h"
n_int command_save(void * ptr, n_string response, n_console_output output_function)
{
return 0;
}
n_int command_open(void * ptr, n_string response, n_console_output output_function)
{
return 0;
}
n_int command_script(void * ptr, n_string response, n_console_output output_function)
{
return 0;
}
#ifdef BRAINCODE_ON
void command_populate_braincode(noble_simulation * local_sim, line_braincode function)
{
}
#endif
n_int command_stop(void * ptr, n_string response, n_console_output output_function)
{
return 0;
}
void sim_change_selected(n_byte forwards)
{
}
void sim_close(void)
{
}
void * sim_init(KIND_OF_USE kind, n_uint randomise, n_uint offscreen_size, n_uint landbuffer_size)
{
return 0L;
}
void sim_cycle(void)
{
}
void sim_flood(void)
{
}
void sim_healthy_carrier(void)
{
}
void sim_realtime(n_uint time)
{
}
n_int sim_new(void)
{
return 0;
}
n_int sim_new_run_condition(void)
{
return 0;
}
void sim_view_options(n_int px, n_int py)
{
}
void sim_rotate(n_int integer_rotation_256)
{
}
void sim_move(n_int rel_vel, n_byte kind)
{
}
n_int sim_view_regular(n_int px, n_int py)
{
return 0;
}
void sim_terrain(n_int sx)
{
}
noble_simulation * sim_sim(void)
{
return 0L;
}
#ifndef _WIN32
n_int sim_thread_console_quit(void)
{
return 0;
}
void sim_thread_console(void)
{
}
#endif
/****************************************************************
NobleMTKRenderer.h
=============================================================
Copyright 1996-2020 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software is a continuing work of Tom Barbalet, begun on
13 June 1996. No apes or cats were harmed in the writing of
this software.
****************************************************************/
#ifdef MUSHROOM
#import "NobleShared.h"
#else
#ifndef NOBLE_PLANET
#ifdef WARFARE
#import "Noble_Warfare-Swift.h"
#else
#import "Simulated_Ape-Swift.h"
#endif
#else
#import "NobleShared.h"
#endif
#endif
@import MetalKit;
// Our platform independent renderer class
@interface NobleMTKRenderer : NSObject<MTKViewDelegate>
- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView
NobleShared:(nonnull NobleShared *)shared;
@end
This diff is collapsed.
/****************************************************************
NobleMTKShaderTypes.h
=============================================================
Copyright 1996-2020 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software is a continuing work of Tom Barbalet, begun on
13 June 1996. No apes or cats were harmed in the writing of
this software.
****************************************************************/
#ifndef NobleMTKShaderTypes_h
#define NobleMTKShaderTypes_h
#include <simd/simd.h>
// Buffer index values shared between shader and C code to ensure Metal shader buffer inputs match
// Metal API buffer set calls
typedef enum NobleMTKVertexInputIndex
{
NobleMTKVertexInputIndexVertices = 0,
NobleMTKVertexInputIndexViewportSize = 1,
} NobleMTKVertexInputIndex;
// Texture index values shared between shader and C code to ensure Metal shader buffer inputs match
// Metal API texture set calls
typedef enum NobleMTKTextureIndex
{
NobleMTKTextureIndexBaseColor = 0,
} NobleMTKTextureIndex;
// This structure defines the layout of each vertex in the array of vertices set as an input to our
// Metal vertex shader. Since this header is shared between our .metal shader and C code,
// we can be sure that the layout of the vertex array in the code matches the layout that
// our vertex shader expects
typedef struct
{
// Positions in pixel space (i.e. a value of 100 indicates 100 pixels from the origin/center)
vector_float2 position;
// 2D texture coordinate
vector_float2 textureCoordinate;
} NobleMTKVertex;
#endif /* NobleMTKShaderTypes_h */
/****************************************************************
NobleMTKShaders.metal
=============================================================